るびべん です:

> ----------------------- Original Message -----------------------
> From:    MENON Jean-Francois <Jean-Francois.MENON / meteo.fr>
> To:      ruby-talk / ruby-lang.org (ruby-talk ML)
> Date:    Mon, 4 Mar 2002 14:24:33 +0900
> Subject: Re: ruby-dev summary 16040-16125

の件ですが、
みねろうさんが、

Hi,

  In mail "Re: ruby-dev summary 16040-16125"
    MENON Jean-Francois <Jean-Francois.MENON / meteo.fr> wrote:

> >       st = Struct.new(:name => 'ruby', :age => 9)

> what is the difference with using Object instance variables ?
> 
>        st = MyStruct.new(name => 'ruby', age => 9)

In your example, MyStruct class must exist before you use it.
But Struct.new(...) way does not need such preparation.

By the way, you cannot use 'name' without quotes or colons.
It should be

         st = MyStruct.new(:name => 'ruby', :age => 9)
                            or
         st = MyStruct.new('name' => 'ruby', 'age' => 9)


> >           return Struct.new(:name => 'ruby, :age => 9)

> what is the difference with:

>           return Hash.new(name => 'ruby', age => 9)

At first, retval.name is 2 chars shorter than retval[:name]  :-).

Second, we can write parameter name in the source code
as syntax (not value). So, for example, typo causes NameError.

-- Minero Aoki

と応えたのに対して、

From:    Dave Thomas <Dave / PragmaticProgrammer.com>
To:      ruby-talk / ruby-lang.org (ruby-talk ML)
Date:    Mon, 4 Mar 2002 15:44:10 +0900
Subject: Re: ruby-dev summary 16040-16125
----

Minero Aoki <aamine / mx.edit.ne.jp> writes:

> > >           return Struct.new(:name => 'ruby', :age => 9)

Interestingly,
                       Struct.new(:name, :age).new('ruby', 9)

is exactly the same length, and works now... Of course it _is_ a tad
ugly.  :)

Dave

という展開になってます。

この先ご興味がある方は、-talk に直接参戦してくだされぃ。


るびべん。