C
Chris Hall
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.senddefine_method, :task, action)
self.class.sendprivate, :task)
end
def do
task
end
end
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.senddefine_method, :task, action)
self.class.sendprivate, :task)
end
def do
task
end
end