33件ヒット
[1-33件を表示]
(0.314秒)
クラス
- BasicObject (11)
- Module (22)
キーワード
-
instance
_ exec (11) -
module
_ exec (11)
検索結果
先頭3件
-
Module
# class _ exec(*args) {|*vars| . . . } -> object (26115.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.foo()... -
Module
# module _ exec(*args) {|*vars| . . . } -> object (11015.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.foo()... -
BasicObject
# instance _ exec(*args) {|*vars| . . . } -> object (8014.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...