るりまサーチ (Ruby 2.5.0)

最速Rubyリファレンスマニュアル検索!
4件ヒット [1-4件を表示] (0.031秒)
トップページ > クラス:Binding[x] > ライブラリ:ビルトイン[x] > バージョン:2.5.0[x] > クエリ:Symbol[x]

別のキーワード

  1. symbol []
  2. symbol slice
  3. win32ole cp_symbol
  4. tracer event_symbol
  5. _builtin symbol

検索結果

Binding#local_variable_get(symbol) -> object (433.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) (433.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#local_variable_defined?(symbol) -> bool (415.0)

引数 symbol で指定した名前のローカル変数が定義されている場合に true を、 そうでない場合に false を返します。

...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...

Binding#local_variables -> [Symbol] (361.0)

ローカル変数の一覧を Symbol の配列で返します。

...カル変数の一覧を Symbol の配列で返します。

//emlist[例][ruby]{
def foo
a = 1
2.times do |n|
binding
.local_variables #=> [:a, :n]
end
end
//}

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

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