Issue #7739 has been updated by david_macmahon (David MacMahon).


=begin
alexeymuranov (Alexey Muranov) wrote:
  > Update: Also, `#reverse_merge!` can be replaced with `#|=`.

This would make the "default values for options" idiom (shown in the example in the reverse_merge! documentation) both cleaner and clearer, IMHO.

Plain Ruby:

  def setup(options = {})
      options = { :size => 25, :velocity => 10 }.merge(options)
  end
 
With reverse_merge!:

  def setup(options = {})
      options.reverse_merge! :size => 25, :velocity => 10
  end

With |=:

  def setup(options = {})
      options |= { :size => 25, :velocity => 10 }
  end

Because Hash#reverse_merge is an ActiveSupport feature, I don't think Hash#| should be an alias for it.  Rather it should be the other way around: implement Hash#| as:

  class Hash
      def |(o)
          o.merge(self)
      end
  end

and then let ActiveSupport make Hash#reverse_merge be an alias to Hash#|.
=end

----------------------------------------
Feature #7739: Define Hash#| as Hash#reverse_merge in Rails
https://bugs.ruby-lang.org/issues/7739#change-41141

Author: alexeymuranov (Alexey Muranov)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: next minor


=begin
I suggest for to define (({Hash#|})) as (({Hash#reverse_merge})) in ((*Rails*)), in my opinion this would correspond nicely to (({Set#|})), to the logical (({#||})) and to the bitwise (({#|})):

  { :a => 1, :b => 2 } | { :b => 1, :c => 2 }  # => { :a => 1, :b => 1, :c => 2 }
=end



-- 
http://bugs.ruby-lang.org/