diff options
author | Michael Herold <opensource@michaeljherold.com> | 2018-09-30 14:07:18 -0500 |
---|---|---|
committer | Michael Herold <opensource@michaeljherold.com> | 2018-09-30 14:59:58 -0500 |
commit | 5b5ed2119d63295fb180ecf1872b9e70e389c831 (patch) | |
tree | 3c80581ee004d9ad31f1981100852ff8063a3066 /lib/hashie/hash.rb | |
parent | 0235a18c14365b69773f99312bad590d0e66ee2d (diff) | |
download | hashie-5b5ed2119d63295fb180ecf1872b9e70e389c831.tar.gz |
[rubocop] Improve our RuboCop setup
Disable Metrics/BlockLength in specs because the length of a block in
the test suite isn't something we want to lint. We want the tests to be
as long as they need to be.
Set an explicit line length metric instead of continually updating this
as we go. Let's pick a max line length that we want to see and stick
with it. This metric should only ever decrease: we don't want to see it
ever increase again.
Diffstat (limited to 'lib/hashie/hash.rb')
-rw-r--r-- | lib/hashie/hash.rb | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/lib/hashie/hash.rb b/lib/hashie/hash.rb index 0eade03..7a97ef6 100644 --- a/lib/hashie/hash.rb +++ b/lib/hashie/hash.rb @@ -18,20 +18,21 @@ module Hashie def to_hash(options = {}) out = {} each_key do |k| - assignment_key = if options[:stringify_keys] - k.to_s - elsif options[:symbolize_keys] - k.to_s.to_sym - else - k - end + assignment_key = + if options[:stringify_keys] + k.to_s + elsif options[:symbolize_keys] + k.to_s.to_sym + else + k + end if self[k].is_a?(Array) out[assignment_key] ||= [] self[k].each do |array_object| - out[assignment_key] << (array_object.is_a?(Hash) ? flexibly_convert_to_hash(array_object, options) : array_object) + out[assignment_key] << maybe_convert_to_hash(array_object, options) end else - out[assignment_key] = self[k].is_a?(Hash) || self[k].respond_to?(:to_hash) ? flexibly_convert_to_hash(self[k], options) : self[k] + out[assignment_key] = maybe_convert_to_hash(self[k], options) end end out @@ -44,6 +45,12 @@ module Hashie private + def maybe_convert_to_hash(object, options) + return object unless object.is_a?(Hash) || object.respond_to?(:to_hash) + + flexibly_convert_to_hash(object, options) + end + def flexibly_convert_to_hash(object, options = {}) if object.method(:to_hash).arity.zero? object.to_hash |