On 8/9/06, Jean Nibee <theopensourceguy / gmail.com> wrote:
> Hi
>
> First off, thanks for letting me be a Ruby noob. I've read most of the
> Pickaxe book and most of Why's guide (whee it's in PDF now) and I am
> getting comfortable w/ Ruby. Coming from a long Java background I tend
> to try and find similarities of things in Ruby to things in Java, simply
> to try and 'get' them better.
>
> Modules have messed me up a bit but here's what I understand. (I'm the
> only Ruby guy at my office so I have no-one to throw these questions off
> of).
>
> Modules in effect 'wrap functionality', they have no other purpose than
> to package up code that can be used/imported/inlined into other code and
> classes. Since you can't instantiate them, they do nothing by
> themselves. They are part of a greater whole.
>
> That being said.. could they be seen (From a functional standpoint) as
> an abstract class? In other words, they are a piece of 'incomplete'
> functionality that we must implement / use and build on but we can't use
> by themselves.
>
> Thanks for your time.

Module can "do" things by themselves if you define some module functions:

module Example
   def self.foo(arg)
      puts arg
   end
end

Example.foo("hello")    # ouputs "hello"

Think of it like this: Modules are like Java interfaces, but with a
method definition provided.

If you want to be more OO generic, Modules are classes that cannot be
instanciated, but otherwise have all the functionality of classes.

Hoping I am not just confusing you.

> P.S. Do you package Modules in a different place than actual classes? (I
> still live like a java programmer and put all my classes in their own
> file.)

You put them where you want.  It's your code after all.

> --
> Posted via http://www.ruby-forum.com/.
>

-- 
"What is your function in life?" - Killer