るりまサーチ

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

別のキーワード

  1. argf.class each_line
  2. argf.class each
  3. argf.class lines
  4. argf.class readline
  5. argf.class readlines

ライブラリ

クラス

検索結果

UnboundMethod#bind(obj) -> Method (18180.0)

self を obj にバインドした Method オブジェクトを生成して返します。

...生成して返します。


@
param obj 自身をバインドしたいオブジェクトを指定します。ただしバインドできるのは、
生成元のクラスかそのサブクラスのインスタンスのみです。

@
raise TypeError objがbindできないオブジェク...
...トである場合に発生します

//emlist[例][ruby]{
# クラスのインスタンスメソッドの UnboundMethod の場合
class
Foo
def foo
"foo"
end
end

# UnboundMethod `m' を生成
p m = Foo.instance_method(:foo) # => #<UnboundMethod: Foo#foo>

# Foo のインスタンスをレ...
...シーバとする Method オブジェクトを生成
p m.bind(Foo.new) # => #<Method: Foo#foo>

# Foo のサブクラス Bar のインスタンスをレシーバとする Method
class
Bar < Foo
end
p m.bind(Bar.new) # => #<Method: Bar(Foo)#foo>


# モジュールのイ...