From: Josh Cheek Date: 2012-05-16T06:53:20+09:00 Subject: Re: I'm looking for a Metaprogramming Project --f46d044402be9993c804c01a393f Content-Type: text/plain; charset=ISO-8859-1 On Tue, May 15, 2012 at 2:41 PM, Phil Stone wrote: > Thanks for all the feedback! > > @Josh Cheek: > > From this spec, I'm not really sure what it's supposed to do. Structs > > are just containers of data, correct? > >> Yes, that's all they are. Implementing Struct is an interesting > >> exercise, though. > But then how are structs different from arrays, if they are used to > store heterogeneous data? Why is there a need to replicate a data type > if it is already implemented in a language? > > Arrays are generic, with methods for dealing with collections. Structs are custom data structures to fit your specific type of data. User = Struct.new :first_name, :last_name user = User.new "Josh", "Cheek" user.first_name # => "Josh" user.last_name # => "Cheek" --f46d044402be9993c804c01a393f Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Tue, May 15, 2012 at 2:41 PM, Phil Stone <lists@ruby-forum.com= > wrote:
Thanks for all the feedback!

@Josh Cheek:
> From this spec, I'm not really sure what it'= s supposed to do. Structs
> are just containers of data, correct?
>> Yes, that's all they are. Implementing Struct is an interestin= g
>> exercise, though.
But then how are structs different from arrays, if they are used to store heterogeneous data? Why is there a need to replicate a data type
if it is already implemented in a language?

<= br>
Arrays are generic, with methods for dealing with collections= . Structs are custom data structures to fit your specific type of data.=A0<= /div>

User =3D Struct.new :first_name, :last_name
<= div>user =3D User.new "Josh", "Cheek"
user.fi= rst_name # =3D> "Josh"
user.last_name # =3D> &quo= t;Cheek"

--f46d044402be9993c804c01a393f--