Skip to content

Instantly share code, notes, and snippets.

@JonRowe
Created February 20, 2014 04:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JonRowe/9107196 to your computer and use it in GitHub Desktop.
Save JonRowe/9107196 to your computer and use it in GitHub Desktop.
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