Module: Kernel
- Defined in:
- lib/gems/json_pure-1.1.3/lib/json/common.rb,
lib/gems/dm-core-0.9.9/lib/dm-core/support/kernel.rb
Instance Method Summary collapse
-
#j(*objs) ⇒ Object
Outputs objs to STDOUT as JSON strings in the shortest form, that is in one line.
-
#jj(*objs) ⇒ Object
Ouputs objs to STDOUT as JSON strings in a pretty format, with indentation and over many lines.
-
#JSON(object, opts = {}) ⇒ Object
If object is string-like parse the string and return the parsed result as a Ruby data structure.
-
#repository(*args) ⇒ Object
Delegates to DataMapper::repository.
Instance Method Details
#j(*objs) ⇒ Object
Outputs objs to STDOUT as JSON strings in the shortest form, that is in one line.
315 316 317 318 319 320 |
# File 'lib/gems/json_pure-1.1.3/lib/json/common.rb', line 315 def j(*objs) objs.each do |obj| puts JSON::generate(obj, :allow_nan => true, :max_nesting => false) end nil end |
#jj(*objs) ⇒ Object
Ouputs objs to STDOUT as JSON strings in a pretty format, with indentation and over many lines.
324 325 326 327 328 329 |
# File 'lib/gems/json_pure-1.1.3/lib/json/common.rb', line 324 def jj(*objs) objs.each do |obj| puts JSON::pretty_generate(obj, :allow_nan => true, :max_nesting => false) end nil end |
#JSON(object, opts = {}) ⇒ Object
If object is string-like parse the string and return the parsed result as a Ruby data structure. Otherwise generate a JSON text from the Ruby data structure object and return it.
The opts argument is passed through to generate/parse respectively, see generate and parse for their documentation.
337 338 339 340 341 342 343 |
# File 'lib/gems/json_pure-1.1.3/lib/json/common.rb', line 337 def JSON(object, opts = {}) if object.respond_to? :to_str JSON.parse(object.to_str, opts) else JSON.generate(object, opts) end end |
#repository(*args) ⇒ Object
Delegates to DataMapper::repository. Will not overwrite if a method of the same name is pre-defined.
4 5 6 7 8 9 10 |
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/support/kernel.rb', line 4 def repository(*args) if block_given? DataMapper.repository(*args) { |*block_args| yield(*block_args) } else DataMapper.repository(*args) end end |