在模块中,是否有任何保留的类名?
module MyLibrary
class Class
end
class Object
end
class Banana < Object
end
end
Ruby并没有似乎感到困惑。
MyLibrary::Object.new.is_a?(::Object)
#=> true
MyLibrary::Class.new.class
#=> MyLibrary::Class
MyLibrary::Class.class
#=> Class
MyLibrary::Banana.new.is_a?(::Object)
#=> true
MyLibrary::Banana.new.is_a?(MyLibrary::Object)
#=> true
MyLibrary::Banana.ancestors
#=> [MyLibrary::Banana, MyLibrary::Object, Object, Kernel, BasicObject]
答案 0 :(得分:4)
就像BEGIN和END这样的红宝石保留词。事实上,他们可能是唯一的两个。
http://docs.ruby-lang.org/en/2.2.0/keywords_rdoc.html
正如FYI Rails有一个单独的保留字列表。