- 23 名前:デフォルトの名無しさん mailto:sage [2008/10/12(日) 06:50:54 ]
- 言語内 DSL とかで、
class Hoge def hoge; "hoge" end; end def foo(&block) a = Hoge.new a.instance_eval(&block) end foo { hoge } # => "hoge" みたいなのは良くあるけど、このやり方だと例えば Shell#transact みたいな、 instance_eval を使う method のブロック内では foo { Shell.new.transact { hoge } } # => NameError: undefined local variable or method `hoge' for #<Shell:0x7fea4b5e00c8> となって期待通りに動いてくれない。こういう場合ってどう対処したら良いんでしょうか?
|

|