I’m attempting to write a DSL for a background worker class, and I’m a little stuck trying to accomplish something.
Ideally, I should be able to write a job worker like the following…
job :job_name do |param1, param2|
puts param1
end
Now, in my worker superclass class, I’m doing something like this…
class Worker
def self.job(job_name, &block)
define_method job_name do
# stuck
end
# do some additional stuff here
end
end
What I want to do is define a method that has access to the block arguments that were used in the original job call, so I could fire this job off with:
Worker.new.job_name(param1, param2)
The method created should be functionally equivalent to:
def job_name(param1, param2)
puts param1
end
Does that make any sense? Hoping someone here can point me in the right direction.
Do you look for something like this: