123456789_123456789_123456789_123456789_123456789_

Module: JSON::GeneratorMethods

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Included In:
Defined in: ext/json/lib/json/common.rb

Class Method Summary

Class Method Details

.to_json(*) ⇒ ? (mod_func)

Converts this object into a ::JSON string. If this object doesn’t directly maps to a ::JSON native type, first convert it to a string (calling #to_s), then 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.

[ GitHub ]

  
# File 'ext/json/lib/json/common.rb', line 1110

def to_json(state = nil, *)
  obj = case self
  when nil, false, true, Integer, Float, Array, Hash
    self
  else
    "#{self}"
  end

  if state.nil?
    JSON::State._generate_no_fallback(obj, nil, nil)
  else
    JSON::State.from_state(state)._generate_no_fallback(obj)
  end
end