るりまサーチ

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

別のキーワード

  1. irb/input-method new
  2. irb/input-method gets
  3. _builtin define_method
  4. irb/input-method encoding
  5. irb/input-method readable_atfer_eof?

ライブラリ

クラス

検索結果

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()...

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()...