--00163630e9672345de0496d33e40
Content-Type: text/plain; charset=ISO-8859-1

On Tue, Dec 7, 2010 at 12:09 PM, Dhruva Sagar <dhruva.sagar / gmail.com>wrote:

> You need to read a bit more on how modules work.
>
> Just to throw some light on your code, if you did a mister_man.crawl, it
> will result in printint out "I'm so slowwww!"
> The methods run & walk are defined in a separate class called
> Module1_Class,
> they will not be available with the Man class instances.
> Man::Module1_Class however is available since the included module adds that
> to Man. Hopefully this should guide you in the right direction.
>

Adding to that, here's a link to the online, somewhat out-of-date but still
useful older version of Programming Ruby:
http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html

Also, does the following help?

module Module1
    # Next section defines a class with the constant Module1_Class;
    # this class has to be accessed from outside this module using
    # Module1::Module1_Class
    # Methods defined in this class are not (?) part of Module1, so
    # won't be "visible" in an instance of a class which includes Module1.
    class Module1_Class
      def run
        puts "I'm running!"
      end
    end
    # next section defines
    def crawl
      puts "I'm so slowwww!"
    end
end

class Man
    # next line makes things in Module1 "visible" to this class
    include Module1
    def jump
      puts "I'm bipedal and I can jump like a fool!"
    end
end

puts
mister_man  an.new
mister_man.run rescue p $!
##<NoMethodError: undefined method `run' for #<Man:0x284680>>
mister_man.crawl rescue p $!
#I'm so slowwww!
mister_man.jump rescue p $!
#I'm bipedal and I can jump like a fool!

puts
modmc  odule1::Module1_Class.new
modmc.run rescue p $!
#I'm running!
modmc.crawl rescue p $!
##<NoMethodError: undefined method `crawl'
        for #<Module1::Module1_Class:0x283860>>
modmc.jump rescue p $!
##<NoMethodError: undefined method `jump'
        for #<Module1::Module1_Class:0x283860>>

puts
manmc  an::Module1_Class.new
manmc.run rescue p $!
#I'm running!
manmc.crawl rescue p $!
##<NoMethodError: undefined method `crawl'
        for #<Module1::Module1_Class:0x1b505e0>>
manmc.jump rescue p $!
##<NoMethodError: undefined method `jump'
        for #<Module1::Module1_Class:0x1b505e0>>

puts
p Module1::Module1_Class
#Module1::Module1_Class
p Man::Module1_Class
#Module1::Module1_Class

--00163630e9672345de0496d33e40--