Jared Beck
Jared Beck

Reputation: 17528

Within a module, are there any reserved class names?

Within a module, are there any reserved class names?

module MyLibrary
  class Class
  end

  class Object
  end

  class Banana < Object
  end
end

Ruby doesn't seem to be confused.

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]

Upvotes: 3

Views: 53

Answers (1)

osman
osman

Reputation: 2469

Just the ruby reserved words like BEGIN and END. In fact they might be the only two.

http://docs.ruby-lang.org/en/2.2.0/keywords_rdoc.html

Just as an FYI Rails has a separate list of reserved words.

Upvotes: 4

Related Questions