This does not seem to work:
class Test
private
define_method :private_method do
"uh!"
end
end
puts Test.new.private_method
This does not seem to work:
class Test
private
define_method :private_method do
"uh!"
end
end
puts Test.new.private_method
Test.instance_eval { private :private_method }
Or, just run
private :private_method
from within the Test
class.
Module#private
takes an optional argument for the method name:
class Test
private :private_method
end
The above is of course equivalent to
Test.private :private_method # doesn't work
Except that Module#private
is private, so you have to use reflection to circumvent the access restrictions:
Test.send :private, :private_method
No eval
necessary.