るりまサーチ

最速Rubyリファレンスマニュアル検索!
36件ヒット [1-36件を表示] (0.036秒)
トップページ > クエリ:object[x] > クエリ:>[x] > クエリ:class_exec[x]

別のキーワード

  1. _builtin >
  2. bigdecimal >
  3. complex >
  4. comparable >
  5. float >

ライブラリ

クラス

キーワード

検索結果

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

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

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

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

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

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

BasicObject#instance_exec(*args) {|*vars| ... } -> object (3207.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...