るりまサーチ

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

別のキーワード

  1. argf.class lines
  2. argf.class each
  3. argf.class each_line
  4. class new
  5. argf.class to_a

クラス

キーワード

検索結果

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

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

...数を指定します。


//emlist[例][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.f...
...oo() #=> 1
//}

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

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

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

...数を指定します。


//emlist[例][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.f...
...oo() #=> 1
//}

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

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