mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
fix HashWithIndifferentAccess.[] method
This commit is contained in:
parent
ea482d366a
commit
2ee28b2bf8
2 changed files with 13 additions and 0 deletions
|
@ -42,6 +42,10 @@ module ActiveSupport
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.[](*args)
|
||||||
|
new.merge(Hash[*args])
|
||||||
|
end
|
||||||
|
|
||||||
alias_method :regular_writer, :[]= unless method_defined?(:regular_writer)
|
alias_method :regular_writer, :[]= unless method_defined?(:regular_writer)
|
||||||
alias_method :regular_update, :update unless method_defined?(:regular_update)
|
alias_method :regular_update, :update unless method_defined?(:regular_update)
|
||||||
|
|
||||||
|
|
|
@ -388,6 +388,15 @@ class HashExtTest < ActiveSupport::TestCase
|
||||||
assert_equal expected, hash
|
assert_equal expected, hash
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_constructor_on_indifferent_access
|
||||||
|
hash = HashWithIndifferentAccess[:foo, 1]
|
||||||
|
assert_equal 1, hash[:foo]
|
||||||
|
assert_equal 1, hash['foo']
|
||||||
|
hash[:foo] = 3
|
||||||
|
assert_equal 3, hash[:foo]
|
||||||
|
assert_equal 3, hash['foo']
|
||||||
|
end
|
||||||
|
|
||||||
def test_reverse_merge
|
def test_reverse_merge
|
||||||
defaults = { :a => "x", :b => "y", :c => 10 }.freeze
|
defaults = { :a => "x", :b => "y", :c => 10 }.freeze
|
||||||
options = { :a => 1, :b => 2 }
|
options = { :a => 1, :b => 2 }
|
||||||
|
|
Loading…
Reference in a new issue