6th Sat
class_evalとclass_execの違い
Rubyを使い初めてから結構たちますが、まだ新しい発見というのはあるものですね。
class_evalでブロックを渡す時に、引数も渡したいと思っていたのですが、
class_execはちょうどその目的に使えるようです。
ruby>>
FOO = lambda{|bar| puts bar}
class Foo
class_exec("Foo", &FOO)
end #=> Foo
<<--
posted by
genki on Sat 6 Aug 2011 at 19:23 with 0 comments