sanemat sanemat - 4 months ago 10
Ruby Question

How to change instance method's visibility

I want to change an instance method's visibility from public to private.

ooo = Object.new
def ooo.some_public; 'woot' end
ooo.some_public # => "woot"
ooo.respond_to?(:some_public) # => true


I want
ooo.some_public
to be private. How can I do that?

Answer
ooo = Object.new
def ooo.some_public; 'woot' end
ooo.respond_to?(:some_public) # => true
ooo.singleton_class.class_eval{private :some_public}
ooo.respond_to?(:some_public) # => false