Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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...
#
#
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