Convert Mash keys for #dig
This commit is contained in:
parent
56cfe95d4b
commit
1433295e22
|
@ -18,7 +18,7 @@ Metrics/AbcSize:
|
|||
# Offense count: 2
|
||||
# Configuration parameters: CountComments.
|
||||
Metrics/ClassLength:
|
||||
Max: 171
|
||||
Max: 176
|
||||
|
||||
# Offense count: 6
|
||||
Metrics/CyclomaticComplexity:
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue