class ActiveSupport::JSON::Encoding::JSONGemEncoder

:nodoc:
:nodoc:

def encode(value)

Encode the given object into a JSON string
def encode(value)
  stringify jsonify value.as_json(options.dup)
end

def initialize(options = nil)

def initialize(options = nil)
  @options = options || {}
end

def jsonify(value)

calls.
to +object.as_json+, not any of this method's recursive +#as_json+
Note: the +options+ hash passed to +object.to_json+ is only passed

or having to remember to call #as_json recursively.
worry about what base types of objects they are allowed to return
This allows developers to implement #as_json without having to

fully JSON-ready object.
Recursively calls #as_json to the object to recursively build a
primitives like Hash, Array, String, Numeric, and true/false/nil.
Convert an object into a "JSON-ready" representation composed of
def jsonify(value)
  case value
  when String
    EscapedString.new(value)
  when Numeric, NilClass, TrueClass, FalseClass
    value.as_json
  when Hash
    Hash[value.map { |k, v| [jsonify(k), jsonify(v)] }]
  when Array
    value.map { |v| jsonify(v) }
  else
    jsonify value.as_json
  end
end

def stringify(jsonified)

Encode a "jsonified" Ruby data structure using the JSON gem
def stringify(jsonified)
  ::JSON.generate(jsonified, quirks_mode: true, max_nesting: false)
end