1

Is the following behavior a bug or a feature?

class A
  def initialize(**options)
    @options = options
  end

  def foo(**options)
    bar(**@options, **options)
  end

  def bar(**options)
  end

  def print
    puts @options.inspect
  end
end

a = A.new(one: 1)
a.print # {:one=>1}

a.foo(two: 2)
a.print # {:one=>1, :two=>2}

Obtained using:

$ ruby -v
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0]

If a feature, where one can read about it? Thank you!

Regards, Ivan

Ivan
  • 153
  • 1
  • 6
  • 1
    I think this a bug that’s been fixed in trunk. See https://bugs.ruby-lang.org/issues/9776, http://stackoverflow.com/questions/23282342/ruby-bug-double-splat-operator-destructively-modifies-hash and https://github.com/ruby/ruby/commit/37e432b5bf4d873a987738891d86f588e97a53a6. – matt May 25 '14 at 20:34
  • Sorry, I didn’t notice that question. Thanks! – Ivan May 25 '14 at 20:44

0 Answers0