為資料建立新結構

Struct 使用指定的屬性和訪問器方法定義新類。

Person = Struct.new :first_name, :last_name

然後,你可以例項化物件並使用它們:

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

person.first_name
# => "John"

person.last_name
# => "Doe"