るりまサーチ

最速Rubyリファレンスマニュアル検索!
318件ヒット [1-100件を表示] (0.072秒)
トップページ > クエリ:i[x] > クエリ:Variable[x] > ライブラリ:ビルトイン[x]

別のキーワード

  1. _builtin to_i
  2. fiddle to_i
  3. matrix elements_to_i
  4. matrix i
  5. ipaddr to_i

検索結果

<< 1 2 3 ... > >>

Object#instance_variable_defined?(var) -> bool (18333.0)

インスタンス変数 var が定義されていたら真を返します。

...emlist[][ruby]{
class Fred
def initialize(p1, p2)
@a, @b = p1, p2
end
end
fred = Fred.new('cat', 99)
p fred.instance_variable_defined?(:@a) #=> true
p fred.instance_variable_defined?("@b") #=> true
p fred.instance_variable_defined?("@c") #=> false
//}

@see Object#instance_variable_ge...
...t,Object#instance_variable_set,Object#instance_variables...

Binding#local_variable_defined?(symbol) -> bool (18233.0)

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

...//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#lo...
...cal_variable_get, Binding#local_variable_set...

Binding#local_variable_set(symbol, obj) (15251.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...
...cal_variable_get(:b) # => 3
p a # => 2
p b # => NameError
end
//}

このメソッドは以下のコード(ただし、obj が Ruby のコードで出力される場
合)と同様の動作をします。

//emlist[][ruby]{
binding.eval("#{sy...
...mbol} = #{obj}")
//}

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

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

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

...ol オブジェクトで指定します。

@raise NameError 引数 symbol で指定したローカル変数が未定義の場合に発生します。

//emlist[例][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_variables -> [Symbol] (15202.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")
//}...

絞り込み条件を変える

Object#instance_variable_get(var) -> object | nil (12233.0)

オブジェクトのインスタンス変数の値を取得して返します。

...ば nil を返します。

@param var インスタンス変数名を文字列か Symbol で指定します。

//emlist[][ruby]{
class Foo
def initialize
@foo = 1
end
end

obj = Foo.new
p obj.instance_variable_get("@foo") #=> 1
p obj.instance_variable_get(:@foo) #=> 1
p obj.instanc...
...e_variable_get(:@bar) #=> nil
//}

@see Object#instance_variable_set,Object#instance_variables,Object#instance_variable_defined?...

Object#instance_variable_set(var, value) -> object (12233.0)

オブジェクトのインスタンス変数 var に値 value を設定します。

...value を返します。

//emlist[][ruby]{
obj = Object.new
p obj.instance_variable_set("@foo", 1) #=> 1
p obj.instance_variable_set(:@foo, 2) #=> 2
p obj.instance_variable_get(:@foo) #=> 2
//}

@see Object#instance_variable_get,Object#instance_variables,Object#instance_variable_defined?...

Module#class_variable_defined?(name) -> bool (12227.0)

name で与えられた名前のクラス変数がモジュールに存在する場合 true を 返します。

...@param name Symbol か String を指定します。

//emlist[例][ruby]{
class Fred
@@foo = 99
end
Fred.class_variable_defined?(:@@foo) #=> true
Fred.class_variable_defined?(:@@bar) #=> false
Fred.class_variable_defined?('@@foo') #=> true
Fred.class_variable_defined?('@@bar') #=> fals...

Object#remove_instance_variable(name) -> object (12227.0)

オブジェクトからインスタンス変数 name を取り除き、そのインス タンス変数に設定されていた値を返します。

...ます。
@raise NameError オブジェクトがインスタンス変数 name を持たない場合に発生します。

//emlist[][ruby]{
class Foo
def foo
@foo = 1
p remove_instance_variable(:@foo) #=> 1
p remove_instance_variable(:@foo) # instance variable @foo not defined (NameErr...
...or)
end
end
Foo.new.foo
//}

@see Module#remove_class_variable,Module#remove_const...

Thread#thread_variable?(key) -> bool (12227.0)

引数 key で指定した名前のスレッドローカル変数が存在する場合に true、そ うでない場合に false を返します。

...ram key 変数名を String か Symbol で指定します。

me = Thread.current
me.thread_variable_set(:oliver, "a")
me.thread_variable?(:oliver) # => true
me.thread_variable?(:stanley) # => false

[注意]: Thread#[] でセットしたローカル変数(Fiber ローカル変数)...
...
対象ではない事に注意してください。

@see Thread#thread_variable_get, Thread#[]...

絞り込み条件を変える

<< 1 2 3 ... > >>