Skip to content

Commit

Permalink
Minor cleanup for ruby 2.7 warnings and failures.
Browse files Browse the repository at this point in the history
  • Loading branch information
zenspider committed Nov 22, 2019
1 parent 8d8e1aa commit ca0ffa5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ rvm:
- 2.4
- 2.5
- 2.6
- 2.7.0-preview2
- ruby-head
- jruby
matrix:
Expand Down
10 changes: 9 additions & 1 deletion lib/json/pure/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,15 @@ def parse_string
def parse_value
case
when scan(FLOAT)
@decimal_class && @decimal_class.new(self[1]) || Float(self[1])
if @decimal_class then
if @decimal_class == BigDecimal then
BigDecimal(self[1])
else
@decimal_class.new(self[1]) || Float(self[1])
end
else
Float(self[1])
end
when scan(INTEGER)
Integer(self[1])
when scan(TRUE)
Expand Down
2 changes: 1 addition & 1 deletion tests/json_parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def test_parse_numbers

def test_parse_bigdecimals
assert_equal(BigDecimal, JSON.parse('{"foo": 9.01234567890123456789}', decimal_class: BigDecimal)["foo"].class)
assert_equal(BigDecimal.new("0.901234567890123456789E1"),JSON.parse('{"foo": 9.01234567890123456789}', decimal_class: BigDecimal)["foo"] )
assert_equal(BigDecimal("0.901234567890123456789E1"), JSON.parse('{"foo": 9.01234567890123456789}', decimal_class: BigDecimal)["foo"] )
end

if Array.method_defined?(:permutation)
Expand Down

0 comments on commit ca0ffa5

Please sign in to comment.