From: halogenandtoast@... Date: 2016-09-05T01:22:41+00:00 Subject: [ruby-core:77150] [Ruby trunk Feature#12719] `Struct#|` for partial updates Issue #12719 has been updated by Matthew Mongeau. File merge_bang.patch added Since merge closely resembles the similar hash function, I think it makes sense to also add `merge!` as a function. I'm not a fan of the mutating methods, but I would find it surprising if this interface was different. Here's an updated patch. I also fixed some of the documentation I wrote. ---------------------------------------- Feature #12719: `Struct#|` for partial updates https://bugs.ruby-lang.org/issues/12719#change-60365 * Author: Matthew Mongeau * Status: Open * Priority: Normal * Assignee: ---------------------------------------- Other languages have operators for performing partial updates on maps. I feel like Struct could be more useful if it provided an easy way of performing partial (or full) updates. After the change you can do the following: ~~~ ruby Point = Struct.new(:x, :y) p = Point.new(1, 2) p2 = p | { y: 4 } p3 = p2 | { x: 10 } puts p.inspect # => # puts p2.inspect # => # puts p3.inspect # => # ~~~ ---Files-------------------------------- struct_update.patch (2.04 KB) struct_merge.patch (2.04 KB) struct_merge_no_segfault.patch (2.19 KB) merge_bang.patch (2.92 KB) -- https://bugs.ruby-lang.org/ Unsubscribe: