From: Chris Hall Date: 2008-02-15T02:57:17+09:00 Subject: lambda/procs and dynamically generated methods I'm not sure one way is technically better than the other, so if anyone has any input, I'd be glad to hear it. class Job def initialize(file = nil) raise "need file or block" if fil.nil? || !block_given? @action = block_given? ? lambda { yield } : eval("lambda { #{IO.read(file)} }") end def do @action.call end end or class Job def initialize(file = nil) raise "need file or block" if fil.nil? || !block_given? action = block_given? ? lambda { yield } : eval("lambda { #{IO.read(file)} }") self.class.send(:define_method, :task, action) self.class.send(:private, :task) end def do task end end -- Posted via http://www.ruby-forum.com/.