A
A
Alexander Gonchurin2014-09-09 11:18:45
ruby
Alexander Gonchurin, 2014-09-09 11:18:45

How to merge two hashes?

There are two hashes:

person1 = { first: "Alex", last: "Go" }
person2 = { first: "Masha", last: "Valeeva" }

Is it possible to change only the value of the last: key using the merge method , or is it better to do it in a smart and simple (Rubive) way?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vsuhachev, 2014-09-09
@imalexgo

person1.merge person2.select {|k,_| %i(last somth_else).include? k }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question