On 5/25/06, Krekna Mektek <krekna / gmail.com> wrote:
> Hi list,
>
> I am reading the "from concepts to code" book from Jacquie Barker, but
> this book uses Java as the language to learn OO programming. This
> doesn't bother me at all although I'm learning Ruby, but sometimes I
> don't  know if it is in Ruby and what it's called in Ruby.
> I am now reading about the concept of Collections, that is Collection
> objects, in Java, but I can't find something about it in my Pickaxe
> book. Does someone know the equivalent in Ruby?

At the most abstract level every programming language needs some form
of "collections" in the sense of data structures used to contain
information. In Ruby there is Array and Hash classes, which can handle
most of what the core Java Collection classes can handle. The
statically typed nature of Java requires such a huge variety of
classes, whereas Ruby gets much of the same functionality with just
two classes.

One benefit of the Java libraries is you can get very specific about
what type of data structure you want to use, even taking into account
the internal representation. For example you can choose to use an
ArrayList or a LinkedList depending on which style of list would be
the most efficient for your needs. Some might argue this is against
the spirit of OO since it exposes the internal representation of the
data structure.

Either way in the case of Ruby core classes, you just have Array and Hash.

> Also another tiny question:
>
> I read in the Pickaxe book :  Integer(gets), how doest this work? I
> thought Integer is an object type and not a method which can indeed be
> called with an argument, like method(argument) ?

The above is actually an Integer method in the Kernel class:

C:\P4WS>ri Kernel#Integer
--------------------------------------------------------- Kernel#Integer
     Integer(arg)    => integer
------------------------------------------------------------------------
     Converts _arg_ to a +Fixnum+ or +Bignum+. Numeric types are
     converted directly (with floating point numbers being truncated).
     If _arg_ is a +String+, leading radix indicators (+0+, +0b+, and
     +0x+) are honored. Others are converted using +to_int+ and +to_i+.
     This behavior is different from that of +String#to_i+.

        Integer(123.999)    #=> 123
        Integer("0x1a")     #=> 26
        Integer(Time.new)   #=> 1049896590

Ryan