Module: JSON::Pure::Generator::GeneratorMethods::Float

Defined in:
lib/json/pure/generator.rb

Instance Method Summary collapse

Instance Method Details

#to_json(state = nil) ⇒ Object

Returns a JSON string representation for this Float number.



389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
# File 'lib/json/pure/generator.rb', line 389

def to_json(state = nil, *)
  state = State.from_state(state)
  case
  when infinite?
    if state.allow_nan?
      to_s
    else
      raise GeneratorError, "#{self} not allowed in JSON"
    end
  when nan?
    if state.allow_nan?
      to_s
    else
      raise GeneratorError, "#{self} not allowed in JSON"
    end
  else
    to_s
  end
end