M
Matthew Pounsett
Hi there.
Apologies if this is covered somewhere... all the googling I've done on =
the subject has wound up with info on class-factories and and using =
variables in methods. Not exactly what I'm looking for.
The question I've got is related to manufacturing methods. In my =
particular case, I'm using a module that relies heavily on callback =
methods. I need to define a couple dozen callbacks which I'd like to =
all behave in basically the same way. In order to keep my code simple, =
I thought I'd try manufacturing them all from the same basic code.. but =
haven't found a syntax that works.
Though this syntax clearly doesn't work, an example of the sort of thing =
I'm looking for might look like this, assuming I want to create the =
methods "on_foo", "on_bar", and "on_baz":
%w( foo bar baz ).each do |callback|
def on_#{callback}
# callback work here
end
end
Is what I'm attempting to do even possible?
Thanks,
Matt
Apologies if this is covered somewhere... all the googling I've done on =
the subject has wound up with info on class-factories and and using =
variables in methods. Not exactly what I'm looking for.
The question I've got is related to manufacturing methods. In my =
particular case, I'm using a module that relies heavily on callback =
methods. I need to define a couple dozen callbacks which I'd like to =
all behave in basically the same way. In order to keep my code simple, =
I thought I'd try manufacturing them all from the same basic code.. but =
haven't found a syntax that works.
Though this syntax clearly doesn't work, an example of the sort of thing =
I'm looking for might look like this, assuming I want to create the =
methods "on_foo", "on_bar", and "on_baz":
%w( foo bar baz ).each do |callback|
def on_#{callback}
# callback work here
end
end
Is what I'm attempting to do even possible?
Thanks,
Matt