Ruby/Hash/update

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск

update is a synonym for merge!

h = {a:1,b:2}     # Using Ruby 1.9 syntax and omitting braces
h.update(b:4,c:9) {|key,old,new| old }  # h is now {a:1, b:2, c:9}
h.update(b:4,c:9) # h is now {a:1, b:4, c:9}