Answer the question
In order to leave comments, you need to log in
How to combine 2 hashes into one in an array?
There is an array with 2 hashes like this
arr = [{:name => "Tom", :surname => "Johns", :age => "100"}, {:name => "Jack", :surname => "Hill", :age => "20"} ]
arr = [{:name => "Tom", :surname => "Johns", :age => "100", :name => "Jack", :surname => "Hill", :age => "20"} ]
arr = {:name => "Tom", :surname => "Johns", :age => "100", :name => "Jack", :surname => "Hill", :age => "20"}
Answer the question
In order to leave comments, you need to log in
Such a Hash cannot be obtained.
Try the line you want to get:
> arr = {:name => "Tom", :surname => "Johns", :age => "100", :name => "Jack", :surname => "Hill", :age => "20"}
(irb):1: warning: key :name is duplicated and overwritten on line 1
(irb):1: warning: key :surname is duplicated and overwritten on line 1
(irb):1: warning: key :age is duplicated and overwritten on line 1
hash = {foo: 42, foo: 43} # => { foo: 42 }
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question