Core Extensions

Methods
Public Instance methods
restore_snapshot(snap)
# File lib/facets/more/snapshot.rb, line 150
  def restore_snapshot(snap) replace(snap) end
take_snapshot()
# File lib/facets/more/snapshot.rb, line 149
  def take_snapshot() dup end
to_json(state = nil, depth = 0)

Returns a JSON string containing a JSON object, that is unparsed from this Hash instance. state is a JSON::State object, that can also be used to configure the produced JSON string output further. depth is used to find out nesting depth, to indent accordingly.

# File lib/facets/more/json.rb, line 499
  def to_json(state = nil, depth = 0)
    state = JSON::State.from_state(state)
    json_check_circular(state) { json_transform(state, depth) }
  end
to_openobject()

Convert a Hash into an OpenObject.

# File lib/facets/more/openobject.rb, line 183
    def to_openobject
      OpenObject.new( self )
    end
Private Instance methods
json_check_circular(state) {|| ...}
# File lib/facets/more/json.rb, line 506
  def json_check_circular(state)
    if state
      state.seen?(self) and raise JSON::CircularDatastructure,
          "circular data structures not supported!"
      state.remember self
    end
    yield
  ensure
    state and state.forget self
  end
json_shift(state, depth)
# File lib/facets/more/json.rb, line 517
  def json_shift(state, depth)
    state and not state.object_nl.empty? or return ''
    state.indent * depth
  end
json_transform(state, depth)
# File lib/facets/more/json.rb, line 522
  def json_transform(state, depth)
    delim = ','
    delim << state.object_nl if state
    result = '{'
    result << state.object_nl if state
    result << map { |key,value|
      json_shift(state, depth + 1) <<
        key.to_s.to_json(state, depth + 1) <<
        ':' << state.space << value.to_json(state, depth + 1)
    }.join(delim)
    result << state.object_nl if state
    result << json_shift(state, depth)
    result << '}'
    result
  end