Skip to content

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

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