Ruby refinements and hooks

I am trying to use ruby ​​refinements to impose rail hooks.

I want to avoid monkey patches. When the monkey patch will work as such

ActiveRecord::Base.class_eval do after_find do # do something with my_method end def my_method # something useful end end 

I got the class way by doing something like this:

 module ActiveRecordRefinements refine ActiveRecord::Base.singleton_class do def my_method #something cool end end end 

But I can not start the hook. I tried using self.used(klass) but didn't seem to be able to get the syntax correctly.

Any help is appreciated.

Thanks.

+7
ruby ruby-on-rails refinements
source share
1 answer

Is there a reason you are not using ActiveSupport callbacks? Have a look here: http://api.rubyonrails.org/classes/ActiveSupport/Callbacks.html

0
source share

All Articles