12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/meta_programming/object.rb', line 12
def safe_alias_method_chain(method_name, ext)
class_eval do
method_name_with_ext = "#{method_name}_with_#{ext}".to_sym
if (method_defined?(method_name_with_ext) && !(metaclass.instance_variable_defined?("@#{method_name_with_ext}")))
if method_defined?(method_name.to_sym)
alias_method_chain(method_name.to_sym, ext.to_sym)
else
alias_method method_name.to_sym, method_name_with_ext
define_method("#{method_name}_without_#{ext}".to_sym) {|*args| }
end
metaclass.instance_variable_set("@#{method_name_with_ext}", true)
end
end
end
|