我有一个像这样的嵌套类:
class Mammal
H = "Mammal"
class Human
H = "Human"
end
end
我想制作一个 Human 对象并在访问 Human 的常量之后,如下所示:
human = Mammal::Human.new # makes an object successfully
puts human::H # does not work **
puts Mammal::Human::H # works ["Human"]
puts Mammal::H # works ["Mammal"]
**.. 但它不起作用(“..不是类/模块 [TypeError]”)。我究竟做错了什么?