|
|
||
-------------------------------------------------------- Object#__send__ obj.send(symbol [, args...]) => obj obj.__send__(symbol [, args...]) => obj ------------------------------------------------------------------------ Invokes the method identified by _symbol_, passing it any arguments specified. You can use __send__ if the name send clashes with an existing method in _obj_. class Klass def hello(*args) "Hello " args.join(' ') end end k = Klass.new k.send :hello, "gentle", "readers" #=> "Hello gentle readers"
Object#__send__ --- send(name[, args ... ]) --- send(name[, args ... ]) { .... } --- __send__(name[, args ... ]) --- __send__(name[, args ... ]) { ... } オブジェクトのメソッド name を、引数に args を 渡して呼び出します。ブロック付きで呼ばれたときはブロックも そのまま引き渡します。メソッド名 name は文字列か Symbol です。 send が再定義された場合に備えて別名 __send__ も 用意されており、ライブラリではこちらを使うべきです。また __send__ は再定義すべきではありません。 send, __send__ は、呼び出し制限 にかかわらず任意のメソッドを呼び出せます。