Skip to content

Instantly share code, notes, and snippets.

@rokob
Created January 10, 2015 00:41
Show Gist options
  • Save rokob/11be3b1eb4ade6321091 to your computer and use it in GitHub Desktop.
Save rokob/11be3b1eb4ade6321091 to your computer and use it in GitHub Desktop.
module A
class B
def shit(x)
puts "I AM THE ORIGINAL #{x}"
x + 1
end
alias_method :oops, :shit
end
end
a = A::B.new.shit(1)
b = A::B.new.oops(1)
module A
class B
alias_method :_old_shit, :shit
def shit(x)
puts "I AM THE NEW SHIT #{x}"
x + 10
end
# alias_method :oops, :shit
end
end
c = A::B.new.shit(1)
d = A::B.new.oops(1)
puts "RESULTS: #{a} - #{b} - #{c} - #{d}"
@rokob
Copy link
Author

rokob commented Jan 10, 2015

With L23 commented out, it prints
RESULTS: 2 - 2 - 11 - 2

With L23 not commented out, it prints
RESULTS: 2 - 2 - 11 - 11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment