Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
metaprogramming with modules in ruby
module One
def a(*)
puts 'One...'
super
end
end
module Two
def a(*)
puts 'Two...'
super
end
end
class Test
def a(*args)
puts 'Zero'
end
end
Test.new.a
#Zero
Test = Class.new Test do
Object.send(:remove_const, :Test)
include One
end
Test.new.a
#One...
#Zero
Test = Class.new Test do
Object.send(:remove_const, :Test)
include Two
end
Test.new.a
#Two...
#One...
#Zero
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.