Reputation: 517
I have an element like this
customers = [{ name: 'John Doe', age: 30, height: 175 }, { name: 'John Doe', age: 30, height: 175 } ... etc]
I know that this is a simple question, but how can I add another customer to this element. ie.
{name: 'Jane' , age: 25, height 150 }
Thanks in advance!
Upvotes: 0
Views: 47
Reputation: 20263
Use the shovel
method:
customers = [{ name: 'John Doe', age: 30, height: 175 }, { name: 'John Doe', age: 30, height: 175 }]
new_customer = {name: 'Jane' , age: 25, height: 150 }
customers << new_customer
=> [{:name=>"John Doe", :age=>30, :height=>175}, {:name=>"John Doe", :age=>30, :height=>175}, {:name=>"Jane", :age=>25, :height=>150}]
Upvotes: 3