Ruby Language Struct Creating new structures for data


Example

Struct defines new classes with the specified attributes and accessor methods.

Person = Struct.new :first_name, :last_name

You can then instantiate objects and use them:

person = Person.new 'John', 'Doe'
# => #<struct Person first_name="John", last_name="Doe">

person.first_name
# => "John"

person.last_name
# => "Doe"