Skip to content

Instantly share code, notes, and snippets.

@jeffomatic
Created February 22, 2013 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffomatic/5015296 to your computer and use it in GitHub Desktop.
Save jeffomatic/5015296 to your computer and use it in GitHub Desktop.
Ruby load ruins whatever clever thing you were doing with alias_method
# 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