るりまサーチ

最速Rubyリファレンスマニュアル検索!
12件ヒット [1-12件を表示] (0.120秒)

別のキーワード

  1. win32ole ole_respond_to?
  2. delegator respond_to?
  3. delegate respond_to?
  4. object respond_to?
  5. _builtin respond_to?

ライブラリ

クラス

検索結果

Object#respond_to?(name, include_all = false) -> bool (18137.0)

オブジェクトがメソッド name を持つとき真を返します。

... File.lchmod の
ような NotImplementedError が発生する場合は false を返します。

※ NotImplementedError が発生する場合に false を返すのは
Ruby
の組み込みライブラリや標準ライブラリなど、C言語で実装されているメソッドのみです。
Ruby
...
...す。

//emlist[][ruby]{
class F
def hello
"Bonjour"
end
end

class D
private
def hello
"Guten Tag"
end
end
list = [F.new,D.new]

list.each{|it| puts it.hello if it.respond_to?(:hello)}
#=> Bonjour

list.each{|it| it.instance_eval("puts hello if it.respond_to?(:hello, true)")}
#=>...
....new.respond_to?(:template_method) # => true
# NotImplementedError が発生しているが、Rubyによる実装部のため true を返す
puts NotImplTemplateMethod.new.respond_to?(:template_method) # => true
# GNU/Linux で実行。C言語による実装部のため false を返す
puts File.res...