Module: RestGraph::Gsub
- Defined in:
- lib/rest-graph/core.rb
Defined Under Namespace
Classes: ParseError
Class Method Summary collapse
Instance Method Summary collapse
- #json_decode(json) ⇒ Object
-
#json_encode(hash) ⇒ Object
only works for flat hash.
Class Method Details
.extended(mod) ⇒ Object
154 155 156 |
# File 'lib/rest-graph/core.rb', line 154 def self.extended mod mod.const_set(:ParseError, Gsub::ParseError) end |
Instance Method Details
#json_decode(json) ⇒ Object
164 165 166 167 |
# File 'lib/rest-graph/core.rb', line 164 def json_decode json raise NotImplementedError.new( 'You need to install either yajl-ruby, json, or json_pure gem') end |
#json_encode(hash) ⇒ Object
only works for flat hash
158 159 160 161 162 163 |
# File 'lib/rest-graph/core.rb', line 158 def json_encode hash middle = hash.inject([]){ |r, (k, v)| r << "\"#{k}\":\"#{v.gsub('"','\\"')}\"" }.join(',') "{#{middle}}" end |