Created
February 22, 2013 17:51
-
-
Save jeffomatic/5015296 to your computer and use it in GitHub Desktop.
Ruby load ruins whatever clever thing you were doing with alias_method
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
# base.rb | |
class Base | |
def foo | |
puts "BASE" | |
end | |
end | |
# derived.rb | |
require "./base" | |
class Derived < Base | |
alias_method :foo_aliased, :foo | |
def foo | |
puts "DERIVED!" | |
end | |
end | |
# From the REPL: | |
load './derived.rb' | |
# => true | |
Derived.new.foo | |
# DERIVED! | |
# => nil | |
Derived.new.foo_aliased | |
# BASE | |
# => nil | |
load './derived.rb' | |
# => true | |
Derived.new.foo | |
# DERIVED! | |
# => nil | |
Derived.new.foo_aliased | |
# DERIVED! | |
# => nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment