Module: JSON::TruffleRuby::Generator::GeneratorMethods::Float
- Defined in:
- lib/json/truffle_ruby/generator.rb
Instance Method Summary collapse
-
#to_json(state = nil, *args) ⇒ Object
Returns a JSON string representation for this Float number.
Instance Method Details
#to_json(state = nil, *args) ⇒ 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 748 749 750 751 752 753 754 755 756 757 758 |
# File 'lib/json/truffle_ruby/generator.rb', line 729 def to_json(state = nil, *args) state = State.from_state(state) if infinite? || nan? if state.allow_nan? to_s elsif state.strict? && state.as_json casted_value = state.as_json.call(self, false) if casted_value.equal?(self) raise GeneratorError.new("#{self} not allowed in JSON", self) end unless Generator.native_type?(casted_value) raise GeneratorError.new("#{casted_value.class} returned by #{state.as_json} not allowed in JSON", casted_value) end state.check_max_nesting state.depth += 1 result = casted_value.to_json(state, *args) state.depth -= 1 result else raise GeneratorError.new("#{self} not allowed in JSON", self) end elsif state.rfc8785? State.rfc8785_number_formatter_proc.call(self) else to_s end end |