るりまサーチ (Ruby 2.3.0)

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

別のキーワード

  1. openssl t61string
  2. asn1 t61string
  3. matrix t
  4. t61string new
  5. fiddle type_size_t

ライブラリ

キーワード

検索結果

Binding#local_variable_get(symbol) -> object (18307.0)

引数 symbol で指定した名前のローカル変数に設定された値を返します。

...][ruby]{
def foo
a = 1
binding
.local_variable_get(:a) # => 1
binding
.local_variable_get(:b) # => NameError
end
//}

このメソッドは以下のコードの短縮形です。

//emlist[][ruby]{
binding
.eval("#{symbol}")
//}

@see Binding#local_variable_set, Binding#local_variable_defined?...

Binding#local_variable_set(symbol, obj) (18307.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.l...
...# => 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 (307.0)

自身をコンテキストとし文字列 expr を Ruby プログラムとして評価しその結果を返します。 組み込み関数 Kernel.#eval を使って eval(expr, self, fname, 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#receiver -> object (307.0)

保持するコンテキスト内での self を返します。

...保持するコンテキスト内での self を返します。

このメソッドは以下のコードと同様の動作をします。

//emlist[][ruby]{
binding
.eval("self")
//}...