Why can I call a private method via Object#send(:private_method)
?
What is the purpose of Ruby's private
keyword if not to prevent direct calling of certain methods?
Is there anyway to reliably prevent objects from being able to call certain methods?
class Person
def say_hi
"hi"
end
private
def private_say_hi
"private hi"
end
end
me = Person.new
me.say_hi
#=> "hi"
me.private_say_hi
#Error: private method `private_say_hi' called for #<Person:0x00558df4b79a08>
me.send(:private_say_hi)
#=> "private hi"