るりまサーチ

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

別のキーワード

  1. fiddle ruby_free
  2. rbconfig ruby
  3. fiddle build_ruby_platform
  4. rake ruby
  5. rubygems/defaults ruby_engine

ライブラリ

クラス

キーワード

検索結果

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

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

...す。


//emlist[例][ruby]{
class Thing
end
c = 1

T
hing.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 (6112.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...

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

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

...す。


//emlist[例][ruby]{
class Thing
end
c = 1

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

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

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