Core Extensions
Methods
Public Instance methods
[ show source ]
# File lib/facets/more/snapshot.rb, line 150 def restore_snapshot(snap) replace(snap) end
[ show source ]
# File lib/facets/more/snapshot.rb, line 149 def take_snapshot() dup end
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.
[ show source ]
# 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
Convert a Hash into an OpenObject.
[ show source ]
# File lib/facets/more/openobject.rb, line 183 def to_openobject OpenObject.new( self ) end
Private Instance methods
[ show source ]
# 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
[ show source ]
# 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
[ show source ]
# 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