33件ヒット
[1-33件を表示]
(0.046秒)
クラス
- BasicObject (11)
- Module (22)
キーワード
-
class
_ exec (11) -
instance
_ exec (11)
検索結果
先頭3件
-
Module
# module _ exec(*args) {|*vars| . . . } -> object (15116.0) -
与えられたブロックを指定された args を引数としてモジュールのコンテキストで評価します。
...ように実行されます。
ローカル変数、定数とクラス変数のスコープはブロックの外側のスコープになります。
@param args ブロックに渡す引数を指定します。
//emlist[例][ruby]{
class Thing
end
c = 1
Thing.class_exec{
def hello()
"Hell......o 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... -
BasicObject
# instance _ exec(*args) {|*vars| . . . } -> object (33.0) -
与えられたブロックをレシーバのコンテキストで実行します。
...できます。
@param args ブロックパラメータに渡す値です。
//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_... -
Module
# class _ exec(*args) {|*vars| . . . } -> object (16.0) -
与えられたブロックを指定された args を引数としてモジュールのコンテキストで評価します。
...ように実行されます。
ローカル変数、定数とクラス変数のスコープはブロックの外側のスコープになります。
@param args ブロックに渡す引数を指定します。
//emlist[例][ruby]{
class Thing
end
c = 1
Thing.class_exec{
def hello()
"Hell......o 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...