defalias_method_chain(target,feature)# Strip out punctuation on predicates or bang methods since # e.g. target?_without_feature is not a valid method name. aliased_target,punctuation=target.to_s.sub(/([?!=])$/,''),$1yield(aliased_target,punctuation)ifblock_given?with_method,without_method="#{aliased_target}_with_#{feature}#{punctuation}","#{aliased_target}_without_#{feature}#{punctuation}"alias_methodwithout_method,targetalias_methodtarget,with_methodcasewhenpublic_method_defined?(without_method)publictargetwhenprotected_method_defined?(without_method)protectedtargetwhenprivate_method_defined?(without_method)privatetargetendend