Convert Mash keys for #dig

This commit is contained in:
Takashi Kokubun 2016-02-06 23:41:55 +09:00 committed by Takashi Kokubun
parent 56cfe95d4b
commit 1433295e22
4 changed files with 19 additions and 2 deletions

View File

@ -18,7 +18,7 @@ Metrics/AbcSize:
# Offense count: 2
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 171
Max: 176
# Offense count: 6
Metrics/CyclomaticComplexity:

View File

@ -12,7 +12,7 @@ scheme are considered to be bugs.
### Added
* Nothing yet.
* [#349](https://github.com/intridea/hashie/pull/349): Convert `Hashie::Mash#dig` arguments for Ruby 2.3.0 - [@k0kubun](https://github.com/k0kubun).
### Changed

View File

@ -250,6 +250,12 @@ module Hashie
self.class.new(other_hash).merge(self)
end
if RUBY_VERSION >= '2.3.0'
def dig(*keys)
super(*keys.map { |key| convert_key(key) })
end
end
protected
def method_name_and_suffix(method_name)

View File

@ -686,4 +686,15 @@ describe Hashie::Mash do
end
end
end
if RUBY_VERSION >= '2.3.0'
describe '#dig' do
subject { described_class.new(a: { b: 1 }) }
it 'accepts both string and symbol as key' do
expect(subject.dig(:a, :b)).to eq(1)
expect(subject.dig('a', 'b')).to eq(1)
end
end
end
end