鉴于以下情况:
class Animal
def self.info
"This is the class '#{self.class.to_s}', and the available breeds are #{BREEDS.to_s}"
end
end
class Dog < Animal
BREEDS = %w(x y z)
end
当我打电话时:
Dog.info
=> This is the class 'Class'
我期待Dog
而不是Class
,我如何从 Animal 获取当前的类名而不放入info
类中Dog
。
另外,我得到undefined constant Animal::BREEDS
我错过了什么?