module JSON::TruffleRuby::Generator::GeneratorMethods::Object
Public Instance Methods
Source
# File vendor/bundle/ruby/3.4.0/gems/json-2.10.2/lib/json/truffle_ruby/generator.rb, line 423 def to_json(state = nil, *) state = State.from_state(state) if state if state&.strict? value = self if state.strict? && !(false == value || true == value || nil == value || String === value || Array === value || Hash === value || Integer === value || Float === value || Fragment === value) if state.as_json value = state.as_json.call(value) unless false == value || true == value || nil == value || String === value || Array === value || Hash === value || Integer === value || Float === value || Fragment === value raise GeneratorError.new("#{value.class} returned by #{state.as_json} not allowed in JSON", value) end value.to_json(state) else raise GeneratorError.new("#{value.class} not allowed in JSON", value) end end else to_s.to_json end end
Converts this object to a string (calling to_s), converts it to a JSON
string, and returns the result. This is a fallback, if no special method to_json
was defined for some object.