Skip to content

Commit

Permalink
Merge pull request #24 from iconara/optimize-falsey
Browse files Browse the repository at this point in the history
Simplify and optimize Util.falsey?
  • Loading branch information
trevorrowe committed Jul 7, 2016
2 parents e164f0b + e3479a7 commit dc01514
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions lib/jmespath/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@ class << self
# https://github.com/jmespath/jmespath.site/blob/master/docs/proposals/improved-filters.rst#and-expressions-1
#
def falsey?(value)
value.nil? ||
value === false ||
value == '' ||
value == {} ||
value == [] ||
(value.respond_to?(:entries) && value.entries.compact.empty?)
!value ||
(value.respond_to?(:empty?) && value.empty?) ||
(value.respond_to?(:entries) && !value.entries.any?)
# final case necessary to support Enumerable and Struct
end

end
end
end

0 comments on commit dc01514

Please sign in to comment.