Skip to content

Commit bc14f74

Browse files
Update numeric.rb
1 parent b3b9aa9 commit bc14f74

File tree

1 file changed

+15
-1
lines changed
  • lib/mongoid/criteria/queryable/extensions

1 file changed

+15
-1
lines changed

lib/mongoid/criteria/queryable/extensions/numeric.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,21 @@ module ClassMethods
4343
# @return [ Integer ] The evolved object.
4444
def evolve(object)
4545
__evolve__(object) do |obj|
46-
obj.to_s.match?(/\A[-+]?[0-9]*[0-9.]0*\z/) ? obj.to_i : Float(obj)
46+
obj = obj.to_s
47+
if str.empty?
48+
nil
49+
else
50+
# These requirements seem a bit odd, but they're explicitly specified
51+
# in the tests, so we're obligated to keep them, for now.
52+
str = str.chop if str.end_with?('.')
53+
if str.empty?
54+
0
55+
else
56+
result = Integer(str) rescue Float(object)
57+
integer = result.to_i
58+
integer == result ? integer : result
59+
end
60+
end
4761
rescue
4862
obj
4963
end

0 commit comments

Comments
 (0)