Guest User

Untitled

a guest
Apr 23rd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. module SWrapper
  2. def self.included(base)
  3. base.send(:include, Wrap)
  4. target = "find"
  5. feature= "wrapping"
  6. base.send(:alias_method, "#{target}_without_#{feature}", target)
  7. base.send(:alias_method, target, "#{target}_with_#{feature}")
  8. end
  9.  
  10. module Wrap
  11. def find_with_wrapping(*args, &block)
  12. puts "Test"
  13. find_without_wrapping(*args, &block)
  14. end
  15. end
  16. end
  17.  
  18. class Person < ActiveRecord::Base
  19. include SWrapper
  20. end
  21.  
  22. doing Person.find 999999999 --> #<NameError: undefined method `find' for class `Person'>
Add Comment
Please, Sign In to add comment