T
Tony Arcieri
[Note: parts of this message were removed to make it a legal post.]
I'm trying to write a method that builds a class and takes arguments from
the outer scope when doing so:
def awesome_mcjobify(state, options = {}, &action)
subject_class = @subject_class
job = Class.new do
metaclass = class << self; self; end
metaclass.send :define_method,
erform do |id|
subject = subject_class.find(id)
action subject
end
metaclass.send :define_method, :action, &action
end
subject_class.const_set "#{state.to_s.camelize}Job", job
end
This is trying to do a lot of things at once and feels icky. It's building a
class that responds to a couple of methods, encapsulates a bit of state
(into the class itself, I guess?), then sticks that class namespaced
underneath another given class.
Refactor me?
I know there's supposed to be define_singleton_method in
1.9, but using define_*method at all (not to mention send :define_method)
seems a lot messier than it could potentially be.
Any suggestions?
I'm trying to write a method that builds a class and takes arguments from
the outer scope when doing so:
def awesome_mcjobify(state, options = {}, &action)
subject_class = @subject_class
job = Class.new do
metaclass = class << self; self; end
metaclass.send :define_method,
subject = subject_class.find(id)
action subject
end
metaclass.send :define_method, :action, &action
end
subject_class.const_set "#{state.to_s.camelize}Job", job
end
This is trying to do a lot of things at once and feels icky. It's building a
class that responds to a couple of methods, encapsulates a bit of state
(into the class itself, I guess?), then sticks that class namespaced
underneath another given class.
Refactor me?
1.9, but using define_*method at all (not to mention send :define_method)
seems a lot messier than it could potentially be.
Any suggestions?