From: ts Date: 2002-01-13T23:42:11+09:00 Subject: Re: Conflicting method names with modules >>>>> "J" == Jonathan Lim writes: J> class ScaleDemo at this step you have ScaleDemo < Object J> include MajorScales ruby will insert the module just before ScaleDemo, this give ScaleDemo < MajorScales < Object J> include PentatonicScales ruby will insert the module just before ScaleDemo, this give ScaleDemo < PentatonicScales < MajorScales < Object J> def initialize J> puts majorNum # Should be 7 J> puts pentaNum # Should be 5 These 2 methods are called in the context of the new object (self), this mean that ruby will set the instance variable for this object. This is why it return 7 in the 2 cases (pentaNum don't change the instance variable if it's always defined) J> testmethod Now ruby search the method #testmethod : it search in ScaleDemo, then in PentatonicScales and find it here. J> end J> end If you define a module function, ruby will create 1) a private method 2) a public singleton method This mean than you can write pigeon% cat b.rb #!/usr/bin/ruby module MajorScales def majorNum 7 end def testmethod puts "MajorScales test method" end module_function :testmethod end module PentatonicScales def pentaNum 5 end def testmethod puts "Pent test method" end module_function :testmethod end class ScaleDemo include MajorScales include PentatonicScales def initialize puts majorNum # Should be 7 puts pentaNum # Should be 5 testmethod PentatonicScales::testmethod MajorScales::testmethod end end ScaleDemo.new pigeon% pigeon% b.rb 7 5 Pent test method Pent test method MajorScales test method pigeon% Guy Decoux