Reputation: 3419
This snippet:
a = private
p a
p a.class
gives me:
Object
Class
I'm not sure whether private
and public
are keywords or methods in Ruby, however, why do they return Object
(I mean the class) ? Is there a historical or practical reason for this odd behavior?
I've tested this with Ruby 2.1, Rubinius 2.2.6 and JRuby 1.7.12.
Upvotes: 4
Views: 51
Reputation: 44715
It's because they are not keywords, but methods defined on Module: http://www.ruby-doc.org/core-2.1.2/Module.html#method-i-private. They return a module which received the call, if you call it in the top level of the application, this receiver is Object class.
Upvotes: 6