why private is not private

why private is not private

Post by Li Che » Tue, 19 Dec 2006 01:37:41


Hi all,

I add a private method to class Object and try to call it from outside
the class. I am confused that it works. Any comments?

Thanks,

Li
##
class Object
private
def method1(arg1)
arg1
end
end

puts "call private method"
puts method1(1)

##
call private method
1

--
Posted via http://www.yqcomputer.com/
 
 
 

why private is not private

Post by David Vall » Tue, 19 Dec 2006 01:43:49


The toplevel execution context is also an instance of Object. You're
still inside an instance of the class you've defined #method1 on.

David Vallner