On Wednesday, April 29, 2015 at 10:46:01 AM UTC-7, Kenny Meyer wrote:
>
> I would like to add another after/before hook to a model dynamically. The 
> way I am approaching this is as follows:
>
>           class_eval do
>             define_method(:after_validation) do |*args|
>               super(*args)
>               # Do something
>             end
>             define_method(:before_save) do |*args|
>               # Do something
>               super(*args)
>             end
>             define_method(:after_save) do |*args|
>               super(*args)
>               # Do something
>             end
>           end
>
> However, this seems to override other after/before hooks. How can I keep 
> the other hooks?
>

As long as you are calling super, you should be fine.  Can you provide an 
example showing that this does not call already defined after/before hooks?

Note that the hooks do not take arguments, so you can drop the *args.

Thanks,
Jeremy 

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to