種類
- インスタンスメソッド (152)
- モジュール関数 (33)
- 定数 (11)
- クラス (11)
クラス
- Binding (78)
- Method (31)
- Module (11)
- Object (11)
- TracePoint (11)
- UnboundMethod (21)
モジュール
- Kernel (33)
キーワード
- === (5)
-
TOPLEVEL
_ BINDING (11) - UnboundMethod (11)
- [] (5)
-
bind
_ call (10) - binding (22)
- call (10)
- eval (33)
-
instance
_ method (11) - irb (8)
-
local
_ variable _ defined? (11) -
local
_ variable _ get (11) -
local
_ variable _ set (11) -
local
_ variables (10) - receiver (10)
-
source
_ location (6) - unbind (11)
検索結果
先頭5件
-
UnboundMethod
# bind(obj) -> Method (21233.0) -
self を obj にバインドした Method オブジェクトを生成して返します。
...self を obj にバインドした Method オブジェクトを生成して返します。
@param obj 自身をバインドしたいオブジェクトを指定します。ただしバインドできるのは、
生成元のクラスかそのサブクラスのインスタンスのみで......se TypeError objがbindできないオブジェクトである場合に発生します
//emlist[例][ruby]{
# クラスのインスタンスメソッドの UnboundMethod の場合
class Foo
def foo
"foo"
end
end
# UnboundMethod `m' を生成
p m = Foo.instance_method(:foo) # => #<UnboundMe......ンスをレシーバとする 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>
# モジュ... -
Object
:: TOPLEVEL _ BINDING -> Binding (12302.0) -
トップレベルでの Binding オブジェクト。
...トップレベルでの Binding オブジェクト。
詳細は Binding を参照してください。... -
UnboundMethod
# bind _ call(recv , *args) -> object (9344.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 (9344.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... -
Method
# unbind -> UnboundMethod (9208.0) -
self のレシーバとの関連を取り除いた UnboundMethod オブ ジェクトを生成して返します。
...self のレシーバとの関連を取り除いた UnboundMethod オブ
ジェクトを生成して返します。
//emlist[例][ruby]{
class Foo
def foo
"foo"
end
end
m = Foo.new.method(:foo) # => #<Method: Foo#foo>
unbound_method = m.unbind # => #<UnboundMethod: Foo#foo>
unbound_method.......bind(Foo.new) # => #<Method: Foo#foo>
//}... -
Binding
# receiver -> object (9202.0) -
保持するコンテキスト内での self を返します。
...保持するコンテキスト内での self を返します。
このメソッドは以下のコードと同様の動作をします。
//emlist[][ruby]{
binding.eval("self")
//}... -
Kernel
. # binding -> Binding (9202.0) -
変数・メソッドなどの環境情報を含んだ Binding オブジェクトを 生成して返します。通常、Kernel.#eval の第二引数として使います。
...変数・メソッドなどの環境情報を含んだ Binding オブジェクトを
生成して返します。通常、Kernel.#eval の第二引数として使います。
//emlist[例][ruby]{
def foo
a = 1
binding
end
eval("p a", foo) #=> 1
//}
@see Kernel.#eval,Object::TOPLEVEL_BINDING... -
TracePoint
# binding -> Binding (9202.0) -
発生したイベントによって生成された Binding オブジェクトを返します。
...発生したイベントによって生成された Binding オブジェクトを返します。
//emlist[例][ruby]{
def foo(ret)
ret
end
trace = TracePoint.new(:call) do |tp|
p tp.binding.local_variables # => [:ret]
end
trace.enable
foo 1
//}... -
TracePoint
# binding -> Binding | nil (9202.0) -
発生したイベントによって生成された Binding オブジェクトを返します。
...た Binding オブジェクトを返します。
C で記述されたメソッドは binding を生成しないため、
:c_call および :c_return イベントに対しては nil を返すことに注意してください。
//emlist[例][ruby]{
def foo(ret)
ret
end
trace = TracePoint.new(:cal......l) do |tp|
p tp.binding.local_variables # => [:ret]
end
trace.enable
foo 1
//}... -
Binding
# local _ variable _ set(symbol , obj) (9132.0) -
引数 symbol で指定した名前のローカル変数に引数 obj を設定します。
...//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.lo......al_variable_get(:b) # => 3
p a # => 2
p b # => NameError
end
//}
このメソッドは以下のコード(ただし、obj が Ruby のコードで出力される場
合)と同様の動作をします。
//emlist[][ruby]{
binding.eval("#{sym......bol} = #{obj}")
//}
@see Binding#local_variable_get, Binding#local_variable_defined?... -
Binding
# eval(expr , fname = _ _ FILE _ _ , lineno = 1) -> object (9102.0) -
自身をコンテキストとし文字列 expr を Ruby プログラムとして評価しその結果を返します。 組み込み関数 Kernel.#eval を使って eval(expr, self, fname, lineno) とするのと同じです。
...トとし文字列 expr を
Ruby プログラムとして評価しその結果を返します。
組み込み関数 Kernel.#eval を使って
eval(expr, self, fname, lineno) とするのと同じです。
@param expr 評価したい式を文字列で与えます。
@param fname ファイル名を......式 expr が fname というファイル名にあるかのように実行されます。
@param lineno 行番号を整数で与えます。式 expr の先頭行の行番号が 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 _ defined?(symbol) -> bool (9102.0) -
引数 symbol で指定した名前のローカル変数が定義されている場合に true を、 そうでない場合に false を返します。
...に true を、
そうでない場合に 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...