るりまサーチ

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

別のキーワード

  1. _builtin end
  2. ripper end_seen?
  3. _builtin exclude_end?
  4. _builtin end_with?
  5. range end

検索結果

<< < 1 2 3 >>

BasicObject#instance_exec(*args) {|*vars| ... } -> object (19.0)

与えられたブロックをレシーバのコンテキストで実行します。

...タに渡す値です。

//emlist[例][ruby]{
class KlassWithSecret
def initialize
@secret = 99
end

end

k = KlassWithSecret.new
# 以下で x には 5 が渡される
k.instance_exec(5) {|x| @secret + x } #=> 104
//}

@see Module#class_exec, Module#module_exec, BasicObject#instance_eval...

Binding#local_variables -> [Symbol] (19.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")
//}...

Module#define_method(name) { ... } -> Symbol (19.0)

インスタンスメソッド name を定義します。

...与えた場合、定義したメソッドの実行時にブロックが
レシーバクラスのインスタンスの上で BasicObject#instance_eval されます。

@param name メソッド名を String または Symbol を指定します。

@param method Proc、Method あるいは UnboundMethod...
...

@raise TypeError method に同じクラス、サブクラス、モジュール以外のメソッ
ドを指定した場合に発生します。

//emlist[例][ruby]{
class Foo
def foo() p :foo end
define_method(:bar, instance_method(:foo))
end

Foo.new.bar # => :foo
//}...

Module#define_method(name, method) -> Symbol (19.0)

インスタンスメソッド name を定義します。

...与えた場合、定義したメソッドの実行時にブロックが
レシーバクラスのインスタンスの上で BasicObject#instance_eval されます。

@param name メソッド名を String または Symbol を指定します。

@param method Proc、Method あるいは UnboundMethod...
...

@raise TypeError method に同じクラス、サブクラス、モジュール以外のメソッ
ドを指定した場合に発生します。

//emlist[例][ruby]{
class Foo
def foo() p :foo end
define_method(:bar, instance_method(:foo))
end

Foo.new.bar # => :foo
//}...

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

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

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

絞り込み条件を変える

Binding#local_variable_get(symbol) -> object (13.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) (13.0)

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

...# => 2
p b # => NameError
end

//}

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

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

@see Binding#local_variable_get,...

Proc#binding -> Binding (13.0)

Proc オブジェクトが保持するコンテキストを Binding オブジェクトで返します。

...Proc オブジェクトが保持するコンテキストを
Binding オブジェクトで返します。

//emlist[例][ruby]{
def fred(param)
proc {}
end


sample_proc = fred(99)
eval
("param", sample_proc.binding) # => 99
//}...
<< < 1 2 3 >>