One way to use send is to bypass visibility, so this is a function, not an error, and in fact you are likely to break the expectations of other programmers using your class if you do not allow this behavior.
However, if you really need it, you can override send and method_missing in your class to implement the desired behavior:
class Access def foo; puts "foo"; end def method_missing(message, *args) puts "Method #{message} missing" end def send(message, *args) if self.class.protected_instance_methods.include?(message) method_missing(message, *args) else super end end protected def bar; puts "bar"; end end a = Access.new a.foo
source share