るりまサーチ

最速Rubyリファレンスマニュアル検索!
11件ヒット [1-11件を表示] (0.032秒)
トップページ > クラス:Object[x] > 種類:インスタンスメソッド[x] > クエリ:method_missing[x]

別のキーワード

  1. irb/input-method gets
  2. irb/input-method new
  3. _builtin define_method
  4. irb/input-method encoding
  5. irb/input-method readable_atfer_eof?

ライブラリ

検索結果

Object#respond_to_missing?(symbol, include_private) -> bool (36.0)

自身が symbol で表されるメソッドに対し BasicObject#method_missing で反応するつもりならば真を返します。

...メソッドに対し
BasicObject#method_missing で反応するつもりならば真を返します。

Object
#respond_to? はメソッドが定義されていない場合、
デフォルトでこのメソッドを呼びだし問合せます。

BasicObject#method_missing を override した場合...
...名シンボル
@param include_private private method も含めたい場合に true が渡されます

//emlist[例][ruby]{
class Sample
def method_missing(name, *args)
if name =~ /^to_*/
[name, *args] # => [:to_sample, "sample args1", "sample args2"]
return
else
super...
...end
end

def respond_to_missing?(sym, include_private)
(sym =~ /^to_*/) ? true : super
end
end

s = Sample.new
s.to_sample("sample args1", "sample args2")
s.respond_to?(:to_sample) # => true
s.respond_to?(:sample) # => false
//}

@see Object#respond_to?, BasicObject#method_missing...