Class: Module
Overview
Correct ‘alias_method_chain_once` implementation
Instance Method Summary collapse
Instance Method Details
#alias_method_chain_once(target, feature) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/dolzenko/alias_method_chain_once.rb', line 5 def alias_method_chain_once(target, feature) aliased_target, punctuation = target.to_s.sub(/([?!=])$/, ''), $1 without_method = "#{aliased_target}_without_#{feature}#{punctuation}" # `method_defined?` matches public and protected methods, # also `*_method_defined?` family of methods is the portable # way to check for method existence, while `public_methods.include?` # will work either on 1.8 or 1.9 (depending on where symbol or string # is provided as method name) unless method_defined?(without_method) || private_method_defined?(without_method) alias_method_chain(target, feature) end end |