This does not seem to work:
class Test
private
define_method :private_method do
"uh!"
end
end
puts Test.new.private_method
The classic way to make class methods private is to open the eigenclass and use the private keyword on the instance methods of the eigenclass — which is what you commonly refer to as class methods.
Use the public_send method when you want to call methods and properties dynamically on other objects. This ensures that you are not calling any private methods or properties.
Ruby Language Metaprogramming send() method send() is used to pass message to object . send() is an instance method of the Object class. The first argument in send() is the message that you're sending to the object - that is, the name of a method. It could be string or symbol but symbols are preferred.
Test.instance_eval { private :private_method }
Or, just run
private :private_method
from within the Test
class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With