module Mixin
def def_a_method
define_method(:foo) { puts 'mixin' }
end
end
class Thing
extend Mixin
def_a_method
def foo
super
end
end
puts Thing.new.foo
# => -:13:in `foo': super: no superclass method `foo' for #<Thing:0x000000018bcf58> (NoMethodError)
# => from -:17:in `<main>'
module Mixin
def def_a_method
include(Module.new do
define_method(:foo) { puts 'mixin' }
end)
end
end
class Thing
extend Mixin
def_a_method
def foo
super
end
end
puts Thing.new.foo
# => mixin