[]

struct[symbol] â anObject
struct[fixnum] â anObject
Instance Public methods

Attribute ReferenceâReturns the value of the instance variable named by symbol, or indexed (0..length-1) by fixnum. Will raise NameError if the named variable does not exist, or 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"
doc_ruby_on_rails
2015-05-16 05:18:49
Comments
Leave a Comment

Please login to continue.