From: Henry Maddocks Date: 2012-05-16T07:57:07+09:00 Subject: Re: I'm looking for a Metaprogramming Project On 16/05/2012, at 10:42 AM, Phil Stone wrote: >> 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" > Sorry that I'm still not clear on this, but how are they then different > from classes? I know you sort of explained this on the spec, but it's > not making much sense to me. They're not different to classes. Struct gives you a quick and easy way to create class like containers without having to define accessor methods. If you need a simple container you could use a Hash except hash uses [] for accessors so any code that expects an object won't like it. An instance of Struct behaves like an Object. Struct creates the accessor methods for you at initialisation time which why implementing Struct is a good exercise for meta programming. I'm getting the impression you need to spend a bit more time with Ruby before you are going to be ready to tackle meta programming. Henry