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

Defined in:
lib/ghi/json.rb

Instance Method Summary collapse

Instance Method Details

#to_json(state = nil) ⇒ Object

Returns a JSON string representation for this Float number.



729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
# File 'lib/ghi/json.rb', line 729

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