59件ヒット
[1-59件を表示]
(0.049秒)
別のキーワード
種類
- インスタンスメソッド (48)
- クラス (11)
クラス
- Module (11)
- Object (22)
- UnboundMethod (15)
キーワード
- UnboundMethod (11)
- bind (5)
-
bind
_ call (10) - method (11)
-
singleton
_ method (11)
検索結果
先頭5件
-
Module
# instance _ method(name) -> UnboundMethod (18139.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!
//}... -
UnboundMethod
# bind _ call(recv , *args) -> object (6128.0) -
self を recv に bind して args を引数として呼び出します。
...self を recv に bind して args を引数として呼び出します。
self.bind(recv).call(*args) と同じ意味です。
//emlist[][ruby]{
puts Kernel.instance_method(:inspect).bind_call(BasicObject.new) # => #<BasicObject:0x000055c65e8ea7b8>
//}
@see UnboundMethod#bind, Method#call... -
UnboundMethod
# bind _ call(recv , *args) { . . . } -> object (6128.0) -
self を recv に bind して args を引数として呼び出します。
...self を recv に bind して args を引数として呼び出します。
self.bind(recv).call(*args) と同じ意味です。
//emlist[][ruby]{
puts Kernel.instance_method(:inspect).bind_call(BasicObject.new) # => #<BasicObject:0x000055c65e8ea7b8>
//}
@see UnboundMethod#bind, Method#call... -
UnboundMethod (56.0)
-
レシーバを持たないメソッドを表すクラスです。 呼び出すためにはレシーバにバインドする必要があります。
...持たないメソッドを表すクラスです。
呼び出すためにはレシーバにバインドする必要があります。
Module#instance_method や
Method#unbind により生成し、後で
UnboundMethod#bind によりレシーバを
割り当てた Method オブジェクトを作る......> Foo.instance_method(:foo),
2 => Foo.instance_method(:bar),
3 => Foo.instance_method(:baz)}
# キーを使って関連するメソッドを呼び出す
# レシーバは任意(Foo クラスのインスタンスでなければならない)
p methods[1].bind(Foo.new).call......ew).call # => "bar"
p methods[3].bind(Foo.new).call # => "baz"
//}
//emlist[例: 以下はメソッドの再定義を UnboundMethod を使って行う方法です。普通は alias や super を使います。][ruby]{
class Foo
def foo
p :foo
end
@@orig_foo = instance_method :fo... -
UnboundMethod
# bind(obj) -> Method (20.0) -
self を obj にバインドした Method オブジェクトを生成して返します。
...のインスタンスメソッドの 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)......のインスタンスメソッドの UnboundMethod の場合
module Foo
def foo
"foo"
end
end
# 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: Bar(Foo)#foo>
//}
@see UnboundMethod#bind_call... -
Object
# method(name) -> Method (14.0) -
オブジェクトのメソッド name をオブジェクト化した Method オブジェクトを返します。
...ror 定義されていないメソッド名を引数として与えると発生します。
//emlist[][ruby]{
me = -365.method(:abs)
p me #=> #<Method: Integer#abs>
p me.call #=> 365
//}
@see Module#instance_method, Method, BasicObject#__send__, Object#send, Kernel.#eval, Object#singleton_method... -
Object
# singleton _ method(name) -> Method (14.0) -
オブジェクトの特異メソッド name をオブジェクト化した Method オブ ジェクトを返します。
...o.new(99)
def k.hi
"Hi, @iv = #{@iv}"
end
m = k.singleton_method(:hi) # => #<Method: #<Demo:0xf8b0c3c4 @iv=99>.hi>
m.call #=> "Hi, @iv = 99"
m = k.singleton_method(:hello) # => NameError
//}
@see Module#instance_method, Method, BasicObject#__send__, Object#send, Kernel.#eval, Object#method...