EdUarDo <eduardo.yanezNOSPAM / NOSPAMgmail.com> writes:

>> You need not put each class in a file. Normally you put
>> each chunk of logically connected code into on file, that
>> may well be more than one class,
>
> Well, that's a point I'd like to ask. Which is the
> philosophy to follow with Ruby projects?. I used to Java
> and C++ projects where a class is defined in a file (two
> for C++).  Is it better to group classes in a single file?

I'd say stick to one class per file in normal cases.
But know that Ruby, like C++ and unlike Java, doesn't care.

>> or in special cases also only half a class. 
>
> What is a half class?

Ruby, unlike both C++ and Java, allows you to reopen classes
after they have been defined.  For example,

   $ cat a-1.rb
   class A
     def foo ; puts 123 end
   end

   $ cat a-2.rb
   class A
     def bar ; puts 456 end
   end

   $ cat main.rb
   require "a-1.rb"
   require "a-2.rb"
   a = A.new
   a.foo
   a.bar

You can do this with core Ruby classes too:

   class Array
     def rest ; self[1..-1] end
   end

   [1,2,3].rest #=> [2,3]

But like I said, just stick to one class per file (and one
file per class) unless you have a good reason not to.
That makes it easy to find any given class, and saves you
from having to think about which classes °»belong together°….

-- 
Daniel Brockman <daniel / brockman.se>

    So really, we all have to ask ourselves:
    Am I waiting for RMS to do this?   --TTN.