Today I Learned

hashrocket A Hashrocket project

Ruby Hash's update method

Today I learned that update is a synonym for merge! for a hash.

a = {x: 1}
a.update({y: 2})
a == {x: 1, y: 2}

I say update is a synonym for merge! but really the C method that they share is called rb_hash_update. So who is the synonym of who? I think the etymology of all the various alias methods in ruby core would be a fun subject. Was map or collect introduced first, etc, etc.

See More #ruby TILs
Looking for help? Each developer at Hashrocket has years of experience working with Ruby applications of all types and sizes. We're an active presence at Ruby conferences, have written some of the most popular gems, and have worked on many of the web's Ruby on Rails success stories. Contact us today to talk about your Ruby project.