Guest User

Untitled

a guest
Feb 21st, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. class Module
  2. def alias_method_chain(target, feature)
  3. # Strip out punctuation on predicates or bang methods since
  4. # e.g. target?_without_feature is not a valid method name.
  5. aliased_target, punctuation = target.to_s.sub(/([?!=])$/, ''), $1
  6. yield(aliased_target, punctuation) if block_given?
  7.  
  8. with_method, without_method = "#{aliased_target}_with_#{feature}#{punctuation}", "#{aliased_target}_without_#{feature}#{punctuation}"
  9.  
  10. alias_method without_method, target
  11. alias_method target, with_method
  12.  
  13. case
  14. when public_method_defined?(without_method)
  15. public target
  16. when protected_method_defined?(without_method)
  17. protected target
  18. when private_method_defined?(without_method)
  19. private target
  20. end
  21. end
  22. end
Add Comment
Please, Sign In to add comment