I want to try out extending a class as explained in
Include vs Extend in Ruby // RailsTips by John Nunemaker
(see the section “A Common Idiom”). Note that I’m NOT talking about
Rails. I just want to understand this feature of Ruby better.
I have as a first step created the following example:
module MixTest
def self.include(base)
base.extend C_Methods
end
module C_Methods
def a_test_method
end
end
end
class Test
include MixTest # Should include a_test_method
end
My undestandig is that
include MixTest
inside Test should invoke self.include, which in turn should add the
methods defined in MixTest.C_Methods to Test.
However, when executing afterwards
p Test.respond_to?(‘a_test_method’)
I get ‘false’. What did I do wrong?