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.



326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
# File 'lib/json/pure/generator.rb', line 326

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