Ruby Programming/Reference/Objects/Struct

= Struct = A structure (Struct) is a:
 * data container, convenient way to bundle a number of attributes together without having to write an explicit class.
 * named collection of data (set of variables) representing a single idea or object.

Inside a 'structure' there is a list of fields - example:
 * Contact: first name, last name, phone, email, birthday.
 * Address: street, city, state, region, postal code, GPS location/coordinates.

Structures are similar to arrays in that they contain multiple data. However, instead of an Index to each piece of data, we have a variable "name". Using the above example:
 * structure (collection of data) = Contact
 * first field in structure 'Contact' is 'first name'

Struct can be used without any additional require statement.

Creating a structure
In Ruby Struct.new takes a set of field names as arguments and returns a new Class.

Class Struct has a method new like other classes. But that method does not return an instance of Struct but rather a class which is a subclass of class Struct. Example: Arguments to Struct.new are names of fields that the generated class will have. These names must be provided as Symbols.


 * 1) approach / method 1
 * 1) approach / method 2

Struct::new returns a new Class object, which can then be used to create specific instances of the new structure. The number of actual parameters must be less than or equal to the number of attributes defined for this class; unset parameters default to nil. Passing too many parameters will raise an ArgumentError.

Comparing structures
Please see the rdoc for Struct. Add any further examples/tutorials here.