クラス
- Binding (52)
- Method (20)
- Module (11)
- UnboundMethod (21)
キーワード
- === (5)
- [] (5)
-
bind
_ call (10) - call (10)
- eval (11)
-
instance
_ method (11) - irb (8)
-
local
_ variable _ defined? (11) -
local
_ variable _ get (11) -
local
_ variable _ set (11)
検索結果
先頭5件
-
UnboundMethod
# bind(obj) -> Method (18152.0) -
self を obj にバインドした Method オブジェクトを生成して返します。
...生成して返します。
@param obj 自身をバインドしたいオブジェクトを指定します。ただしバインドできるのは、
生成元のクラスかそのサブクラスのインスタンスのみです。
@raise TypeError objがbindできないオブジェク......スをレシーバとする 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>
# モジュー......を生成
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>
//}......_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... -
UnboundMethod
# bind _ call(recv , *args) -> object (6145.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 (6145.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... -
Binding
# local _ variable _ set(symbol , obj) (3051.0) -
引数 symbol で指定した名前のローカル変数に引数 obj を設定します。
...設定します。
@param symbol ローカル変数名を Symbol オブジェクトで指定します。
@param obj 引数 symbol で指定したローカル変数に設定するオブジェクトを指定します。
//emlist[例][ruby]{
def foo
a = 1
bind = binding
bind.local_variable_set......(:a, 2) # set existing local variable `a'
bind.local_variable_set(:b, 3) # create new local variable `b'
# `b' exists only in binding
p bind.local_variable_get(:a) # => 2
p bind.local_variable_get(:b) # => 3
p a # => 2
p b......# => NameError
end
//}
このメソッドは以下のコード(ただし、obj が Ruby のコードで出力される場
合)と同様の動作をします。
//emlist[][ruby]{
binding.eval("#{symbol} = #{obj}")
//}
@see Binding#local_variable_get, Binding#local_variable_defined?... -
Binding
# eval(expr , fname = _ _ FILE _ _ , lineno = 1) -> object (3027.0) -
自身をコンテキストとし文字列 expr を Ruby プログラムとして評価しその結果を返します。 組み込み関数 Kernel.#eval を使って eval(expr, self, fname, lineno) とするのと同じです。
...ame, lineno) とするのと同じです。
@param expr 評価したい式を文字列で与えます。
@param fname ファイル名を文字列で与えます。式 expr が fname というファイル名にあるかのように実行されます。
@param lineno 行番号を整数で与えま......の先頭行の行番号が lineno であるかのように実行されます。
//emlist[例][ruby]{
def get_binding(str)
binding
end
str = "hello"
p eval("str + ' Fred'") #=> "hello Fred"
p get_binding("bye").eval("str + ' Fred'") #=> "bye Fred"
//}
@see Kernel.#eval... -
Binding
# local _ variable _ get(symbol) -> object (3021.0) -
引数 symbol で指定した名前のローカル変数に設定された値を返します。
...ます。
@param symbol ローカル変数名を Symbol オブジェクトで指定します。
@raise NameError 引数 symbol で指定したローカル変数が未定義の場合に発生します。
//emlist[例][ruby]{
def foo
a = 1
binding.local_variable_get(:a) # => 1
binding.local_v......ariable_get(:b) # => NameError
end
//}
このメソッドは以下のコードの短縮形です。
//emlist[][ruby]{
binding.eval("#{symbol}")
//}
@see Binding#local_variable_set, Binding#local_variable_defined?... -
Binding
# local _ variable _ defined?(symbol) -> bool (3015.0) -
引数 symbol で指定した名前のローカル変数が定義されている場合に true を、 そうでない場合に false を返します。
...rue を、
そうでない場合に false を返します。
@param symbol ローカル変数名を Symbol オブジェクトで指定します。
//emlist[例][ruby]{
def foo
a = 1
binding.local_variable_defined?(:a) # => true
binding.local_variable_defined?(:b) # => false
end
//}
この......メソッドは以下のコードの短縮形です。
//emlist[][ruby]{
binding.eval("defined?(#{symbol}) == 'local-variable'")
//}
@see Binding#local_variable_get, Binding#local_variable_set... -
Binding
# irb -> object (3009.0) -
REPLのセッションを開始します。
...REPLのセッションを開始します。
2.5.0 からは require 'irb' せずに直接 binding.irb を呼び出しても使えるようになりました。
@see irb... -
Method
# ===(*args) -> object (27.0) -
メソッドオブジェクトに封入されているメソッドを起動します。
...されたもので、Array#[]のような
他の [] メソッドとの意味的な関連性はありません。
@param args self に渡される引数。
@see UnboundMethod#bind_call
@see spec/safelevel
//emlist[例][ruby]{
class Foo
def foo(arg)
"foo called with arg #{arg}"
end
end
m... -
Method
# [](*args) -> object (27.0) -
メソッドオブジェクトに封入されているメソッドを起動します。
...されたもので、Array#[]のような
他の [] メソッドとの意味的な関連性はありません。
@param args self に渡される引数。
@see UnboundMethod#bind_call
@see spec/safelevel
//emlist[例][ruby]{
class Foo
def foo(arg)
"foo called with arg #{arg}"
end
end
m... -
Method
# call(*args) -> object (27.0) -
メソッドオブジェクトに封入されているメソッドを起動します。
...されたもので、Array#[]のような
他の [] メソッドとの意味的な関連性はありません。
@param args self に渡される引数。
@see UnboundMethod#bind_call
@see spec/safelevel
//emlist[例][ruby]{
class Foo
def foo(arg)
"foo called with arg #{arg}"
end
end
m... -
Method
# call(*args) { . . . } -> object (27.0) -
メソッドオブジェクトに封入されているメソッドを起動します。
...されたもので、Array#[]のような
他の [] メソッドとの意味的な関連性はありません。
@param args self に渡される引数。
@see UnboundMethod#bind_call
@see spec/safelevel
//emlist[例][ruby]{
class Foo
def foo(arg)
"foo called with arg #{arg}"
end
end
m... -
Module
# instance _ method(name) -> UnboundMethod (27.0) -
self のインスタンスメソッド name をオブジェクト化した UnboundMethod を返します。
...オブジェクト化した UnboundMethod を返します。
@param name メソッド名を Symbol または String で指定します。
@raise NameError self に存在しないメソッドを指定した場合に発生します。
@see Module#public_instance_method, Object#method
//emlist[例]......d(: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!
//}... -
Method
# ===(*args) -> object (21.0) -
メソッドオブジェクトに封入されているメソッドを起動します。
...意されたもので、Array#[]のような
他の [] メソッドとの意味的な関連性はありません。
@param args self に渡される引数。
@see UnboundMethod#bind_call
//emlist[例][ruby]{
class Foo
def foo(arg)
"foo called with arg #{arg}"
end
end
m = Foo.new.method(... -
Method
# [](*args) -> object (21.0) -
メソッドオブジェクトに封入されているメソッドを起動します。
...意されたもので、Array#[]のような
他の [] メソッドとの意味的な関連性はありません。
@param args self に渡される引数。
@see UnboundMethod#bind_call
//emlist[例][ruby]{
class Foo
def foo(arg)
"foo called with arg #{arg}"
end
end
m = Foo.new.method(...