Created
February 20, 2014 04:41
-
-
Save JonRowe/9107196 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
module B | |
def a | |
puts 'b' | |
super | |
end | |
end | |
class A | |
class << self; prepend B; end | |
def self.a | |
puts 'a' | |
end | |
end | |
class << A | |
def a | |
puts 'c' | |
super | |
end | |
end | |
A.a | |
# => | |
# b | |
# c | |
# prepend_class.rb:18:in `a': super: no superclass method `a' for A:Class (NoMethodError) | |
# from prepend_class.rb:4:in `a' | |
# from prepend_class.rb:22:in `<main>' | |
# | |
# I'm assuming this is because the singleton class is the class, so it redefines the method rather than overriding... | |
# | |
# |
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
module B | |
def a | |
puts 'b' | |
super | |
end | |
end | |
class A | |
prepend B | |
def a | |
puts 'a' | |
end | |
end | |
a = A.new | |
class << a | |
def a | |
puts 'c' | |
super | |
end | |
end | |
a.a | |
# => | |
# c | |
# b | |
# a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment