Skip to content

Instantly share code, notes, and snippets.

@zmoazeni
Forked from svenfuchs/gist:132576
Created June 19, 2009 12:22
Show Gist options
  • Save zmoazeni/132587 to your computer and use it in GitHub Desktop.
Save zmoazeni/132587 to your computer and use it in GitHub Desktop.
class A
def foo
puts 'original'
end
alias bar foo
def foo
puts 'modified'
end
end
A.new.bar # => "original"
# -------------------------------------
class A
def foo
puts 'original'
end
end
class B < A
alias bar foo
end
class A
def foo
puts 'modified'
end
end
B.new.bar # => "original"
# -------------------------------------
class Object
class << self
def alias_method_no_copy(new_method, original_method)
class_eval <<-EOF
def #{new_method.to_s}(*opts)
#{original_method.to_s}(*opts)
end
EOF
end
end
end
class A
def foo
puts 'original'
end
end
class B < A
alias_method_no_copy :bar, :foo
end
class A
def foo
puts 'modified'
end
end
B.new.foo # => "modified"
B.new.bar # => "modified"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment