method
[]
[](p1)
public
Attribute Reference—Returns the value of the given struct member or the member at the given index. Raises NameError if the member does not exist and IndexError if the index is out of range.
Customer = Struct.new(:name, :address, :zip) joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345) joe["name"] #=> "Joe Smith" joe[:name] #=> "Joe Smith" joe[0] #=> "Joe Smith"