Skip to content

Commit

Permalink
Merge pull request rails#5566 from lest/patch-3
Browse files Browse the repository at this point in the history
fix HashWithIndifferentAccess.[] method
  • Loading branch information
drogus committed Mar 25, 2012
2 parents 64ccb59 + 2ee28b2 commit a4bf304
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Expand Up @@ -42,6 +42,10 @@ def self.new_from_hash_copying_default(hash)
end
end

def self.[](*args)
new.merge(Hash[*args])
end

alias_method :regular_writer, :[]= unless method_defined?(:regular_writer)
alias_method :regular_update, :update unless method_defined?(:regular_update)

Expand Down
9 changes: 9 additions & 0 deletions activesupport/test/core_ext/hash_ext_test.rb
Expand Up @@ -388,6 +388,15 @@ def test_store_on_indifferent_access
assert_equal expected, hash
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
defaults = { :a => "x", :b => "y", :c => 10 }.freeze
options = { :a => 1, :b => 2 }
Expand Down

0 comments on commit a4bf304

Please sign in to comment.