diff options
| author | Michael Herold <michael.j.herold@gmail.com> | 2018-02-03 10:23:14 -0600 |
|---|---|---|
| committer | Michael Herold <michael.j.herold@gmail.com> | 2018-06-17 11:04:56 -0500 |
| commit | 5a6ffc7e2df076c266c322ae9272b098b3ab40ed (patch) | |
| tree | 578b274928ce6ac710922c85d050771f52753736 /lib/hashie/hash.rb | |
| parent | 8fc10095fc409f4db495713c92c0cf8e31d3bfc1 (diff) | |
| download | hashie-5a6ffc7e2df076c266c322ae9272b098b3ab40ed.tar.gz | |
Update Rubocop and address the addressable todos
This is a big step forward in our Rubocop setup. I addressed all of the todos
from the current version of Rubocop that made sense to. The only things that
remain are metrics and one cop that relies on the line length metric to work.
I made some judgment calls on disabling a few cops:
1. The `Layout/IndentHeredoc` cop wants you to either use the squiggly heredoc
from Ruby 2.3 or introduce a library. Since we are a low-level library that
is used as a transitive dependency, we cannot introduce another library as a
dependence, so that option is out. Also, we support Rubies back to 2.0
currently, so using the squiggly heredoc isn't an option. Once we remove
support for Rubies older than 2.3, we can switch to the squiggly heredoc cop.
2. The `Naming/FileName` cop was reporting false positives for a few files in
the repository, so I disabled it on those files.
3. The `Style/DoubleNegation` cop reports lints on a few cases where we use
double negation. Given the very generic nature of Hashie, the double-negation
is the easiest, clearest way to express that we want an item to be a Boolean.
I disabled the cop because we exist in the gray area where this makes sense.
Diffstat (limited to 'lib/hashie/hash.rb')
| -rw-r--r-- | lib/hashie/hash.rb | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/hashie/hash.rb b/lib/hashie/hash.rb index 87e1923..0eade03 100644 --- a/lib/hashie/hash.rb +++ b/lib/hashie/hash.rb @@ -17,7 +17,7 @@ module Hashie # Converts a mash back to a hash (with stringified or symbolized keys) def to_hash(options = {}) out = {} - keys.each do |k| + each_key do |k| assignment_key = if options[:stringify_keys] k.to_s elsif options[:symbolize_keys] @@ -28,10 +28,10 @@ module Hashie if self[k].is_a?(Array) out[assignment_key] ||= [] self[k].each do |array_object| - out[assignment_key] << (Hash === array_object ? flexibly_convert_to_hash(array_object, options) : array_object) + out[assignment_key] << (array_object.is_a?(Hash) ? flexibly_convert_to_hash(array_object, options) : array_object) end else - out[assignment_key] = (Hash === self[k] || self[k].respond_to?(:to_hash)) ? flexibly_convert_to_hash(self[k], options) : self[k] + out[assignment_key] = self[k].is_a?(Hash) || self[k].respond_to?(:to_hash) ? flexibly_convert_to_hash(self[k], options) : self[k] end end out @@ -45,7 +45,7 @@ module Hashie private def flexibly_convert_to_hash(object, options = {}) - if object.method(:to_hash).arity == 0 + if object.method(:to_hash).arity.zero? object.to_hash else object.to_hash(options) |
