how to dynamically call a method while respecting privacy

reflection, ruby, visibility

Solution

As I know - you need method public_send:

----------------------------------------------------- Object#public_send
     obj.public_send(symbol [, args...])  => obj

     From Ruby 1.9.1
------------------------------------------------------------------------
     Invokes the method identified by _symbol_, passing it any arguments
     specified. Unlike send, public_send calls public methods only.

        1.public_send(:puts, "hello")  # causes NoMethodError

Problem

Using dynamic method calls (`#send` or `#method`) the methods' visibility is ignored. Is there a simple way to dynamically call a method that will fail calling a private method?

Original source