Ruby Language Struct Creating new structures for data

30% OFF - 9th Anniversary discount on Entity Framework Extensions until December 15 with code: ZZZANNIVERSARY9

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"


Got any Ruby Language Question?