るりまサーチ

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

別のキーワード

  1. module attr
  2. module new
  3. module module_eval
  4. _builtin module_eval
  5. module class_eval

ライブラリ

クラス

検索結果

Module#module_exec(*args) {|*vars| ... } -> object (21202.0)

与えられたブロックを指定された args を引数としてモジュールのコンテキストで評価します。

...[ruby]{
class Thing
end
c = 1

Thing.class_exec{
def hello()
"Hello there!"
end

define_method(:foo) do # ローカル変数がブロックの外側を参照している
c
end
}

t = Thing.new
p t.hello() #=> "Hello there!"
p t.foo() #=> 1
//}

@see Module...
...#module_eval, Module#class_eval...

Module#class_exec(*args) {|*vars| ... } -> object (3002.0)

与えられたブロックを指定された args を引数としてモジュールのコンテキストで評価します。

...[ruby]{
class Thing
end
c = 1

Thing.class_exec{
def hello()
"Hello there!"
end

define_method(:foo) do # ローカル変数がブロックの外側を参照している
c
end
}

t = Thing.new
p t.hello() #=> "Hello there!"
p t.foo() #=> 1
//}

@see Module...
...#module_eval, Module#class_eval...