るりまサーチ

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

別のキーワード

  1. csv instance
  2. _builtin instance_eval
  3. prime instance
  4. syslog instance
  5. singleton instance

ライブラリ

クラス

検索結果

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

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

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

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

# UnboundMethod `m' を生成
p m = Foo.instance_method(:foo) # => #<Unbound...
...スをレシーバとする 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>


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

# Foo をインクルードしたクラス Bar のインスタンスをレシーバと
# する Method オブジェクトを生成
class
Bar
include Foo
end
p m.bind(Bar.new) # => #<Method:...

Module#instance_method(name) -> UnboundMethod (18144.0)

self のインスタンスメソッド name をオブジェクト化した UnboundMethod を返します。

...#public_instance_method, Object#method

//emlist[例][ruby]{
class
Interpreter
def do_a() print "there, "; end
def do_d() print "Hello "; end
def do_e() print "!\n"; end
def do_v() print "Dave"; end
Dispatcher = {
"a" => instance_method(:do_a),
"d" => instance_method(:do_d)...
...,
"e" => instance_method(:do_e),
"v" => instance_method(:do_v)
}
def interpret(string)
string.each_char {|b| Dispatcher[b].bind(self).call }
end
end

interpreter = Interpreter.new
interpreter.interpret('dave')
# => Hello there, Dave!
//}...