Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Object#public_send
(::interned name, *untyped, **untyped) ?{ (?) -> untyped } -> untyped
obj.public_send(symbol [, args...]) → obj
obj.public_send(string [, args...]) → obj
vm_eval.c
View on GitHub ↗
static VALUE
rb_f_public_send(int argc, VALUE *argv, VALUE recv)
{
return send_internal_kw(argc, argv, recv, CALL_PUBLIC);
}
Invokes the method identified by symbol, passing it any arguments specified. Unlike send, public_send calls public methods only. When the method is identified by a string, the string is converted to a symbol.
Example
1.public_send(:puts, "hello") # causes NoMethodError
See also
#public_methods
#remove_instance_variable
#public_method
#respond_to?
also in
4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0