Permalink
Browse files

Leave nonconvertible keys untouched when symbolizing keys.

  • Loading branch information...
1 parent e486c2b commit c400fdf95ea8c652f0176b9b81c4e3a12232f6db @splattael splattael committed Aug 22, 2013
Showing with 7 additions and 1 deletion.
  1. +1 −1 lib/powerpack/hash/symbolize_keys.rb
  2. +6 −0 spec/powerpack/hash/symbolize_keys_spec.rb
@@ -7,7 +7,7 @@ class Hash
# @example
# { 'one' => 1, 'two' => 2 }.symbolize_keys #=> { :one => 1, :two => 2 }
def symbolize_keys
- Hash[map { |(k, v)| [k.to_sym, v] }]
+ Hash[map { |(k, v)| [(k.to_sym rescue k), v] }]
end
end
end
@@ -6,4 +6,10 @@
expect(hash.symbolize_keys).to eq({ one: 1, two: 2 })
end
+
+ it 'leaves nonconvertible keys untouched' do
+ hash = { 1 => 'one', [1, 1] => 'ones' }
+
+ expect(hash.symbolize_keys).to eq({ 1 => 'one', [1, 1] => 'ones' })
+ end
end

0 comments on commit c400fdf

Please sign in to comment.