From: Minero Aoki Date: 2002-03-04T15:04:52+09:00 Subject: Re: ruby-dev summary 16040-16125 Hi, In mail "Re: ruby-dev summary 16040-16125" MENON Jean-Francois 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