Call value of 'send' with ': public' in Ruby

In Ruby you can do ...

Object.send(:public, *Object.private_instance_methods)

... as seen in this answer to another question . This overrides each of the private instance methods Object, making them publicly available. My question is: how does it work? sendshould work with the method name, but it seems that there are no methods with the name public, privateor protected, defined on Object(or at least my search fu hasn't found them).

> Object.respond_to?(:public)
=> false 
+4
source share
1 answer

public, Module. , Object Class, Class - Module: ruby ​​ ruby.

respond_to? check false, respond_to? ( ruby ​​2.0 ). ,

Object.respond_to?(:public, true)

true.

+4

Source: https://habr.com/ru/post/1613406/


All Articles