From: shevegen@... Date: 2016-09-19T02:02:02+00:00 Subject: [ruby-core:77307] [Ruby trunk Feature#12770] Hash#left_merge Issue #12770 has been updated by Robert A. Heiler. I think that the name appears to be a bit strange - if we have a left_merge, do we have a right_merge, an up_merge, a bottom_merge? :) I can relate an example from molecular biology by the way, and how they "find names". :D There was a dude from the UK called Southern, Edwin Southern specifically; the "Southern Blot" technique is named after him: https://en.wikipedia.org/wiki/Southern_blot In short, this technique allows you to "put" DNA onto a blot ("blotting"). This can then be used to hybridize with a probe. Anyway, a bit later the same was done for RNA. What name was given for this? Northern blotting! But not because someone was called "Northern", but simply because there already now was a Southern Technique. So it would make sense to call the RNA-version Northern blotting. :D And to complete this funny roundabout, a bit later a technique for proteins was added, immuno-blotting (via antibodies); they called this "Western blotting". They are still trying to find an "Eastern Blotting" technique, which is not so trivial (DNA, RNA and proteins are already covered after all), just to complete the four directions. Good that we do not have more than four major directions... :D Anyway to conclude this lengthy and possibly not so useful comment, names do matter! ---------------------------------------- Feature #12770: Hash#left_merge https://bugs.ruby-lang.org/issues/12770#change-60546 * Author: Derek Kniffin * Status: Feedback * Priority: Normal * Assignee: ---------------------------------------- I would like a Hash method that does the following: ````ruby a = {a: 1, b: nil, c: nil, d: nil} b = {a: 1, b: 2, c: nil} a.left_merge(b) # => {a: 1, b: 2, c: nil, d: nil} ```` So, it takes the first hash, and for any values that are nil, if there's a value for that key in the second hash, fill in the value from the second hash. I've searched around a bit, and I haven't found this anywhere, so I'd like to propose a new one: `Hash#left_merge`. I've also got a first draft of the method definition: ````ruby class Hash def left_merge(new_hash) merge(new_hash) { |_, old_v, new_v| old_v || new_v } end end ```` -- https://bugs.ruby-lang.org/ Unsubscribe: