From: nobu@... Date: 2016-09-02T15:38:22+00:00 Subject: [ruby-core:77131] [Ruby trunk Feature#12719] `Struct#|` for partial updates Issue #12719 has been updated by Nobuyoshi Nakada. In your example, the value in the LHS is ignored when the same key is present in the RHS hash. It doesn't feel nice as `|` operator. `merge` sounds nice in that sense, but your patch would segfault at `p.merge(0)`. ---------------------------------------- Feature #12719: `Struct#|` for partial updates https://bugs.ruby-lang.org/issues/12719#change-60349 * 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) -- https://bugs.ruby-lang.org/ Unsubscribe: