-
-
Save zmoazeni/132587 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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