yarv-dev:1064
From: sheepman <sheepman sheepman.sakura.ne.jp>
Date: Sat, 22 Jul 2006 16:21:06 +0900
Subject: [yarv-dev:1064] open> class_eval in class method
こんにちは、sheepman です。
クラスメソッドの中で、クラスにメソッドを定義するために class_eval を
呼ぶと、定義されたメソッドが private になります。module_eval でも
同様です。
$ cat t.rb
class C
def self.def_mthd(&b)
class_eval(&b)
end
end
C.def_mthd {
def answer()
'kotae'
end
}
p C.new.answer
$ ruby-2.0 -v t.rb
ruby 2.0.0 (Base: Ruby 1.9.0 2006-04-08) [i686-linux]
YARVCore 0.4.1 Rev: 527 (2006-07-19) [opts: [direct threaded code] [inline method cache] ]
t.rb:13:in `<main>': private method `answer' called for #<C:0x40295d5c> (NoMethodError)
$ ruby-1.9 -v t.rb
ruby 1.9.0 (2006-07-19) [i686-linux]
"kotae"
$ ruby-1.8 -v t.rb
ruby 1.8.5 (2006-07-21) [i686-linux]
"kotae"
--
sheepman / TAMURA Takashi
sheepman sheepman.sakura.ne.jp
--
ML: yarv-dev quickml.atdot.net
Info: http://www.atdot.net/~ko1/quickml
-> 1064 2006-07-22 16:21 [sheepman sheepman.sa] open> class_eval in class method 1087 2006-08-19 00:47 ┗[ko1 atdot.net ]