Method: PSON.dump
- Defined in:
- lib/puppet/external/pson/common.rb
.dump(obj, anIO = nil, limit = nil) ⇒ Object
Dumps obj as a PSON string, i.e. calls generate on the object and returns the result.
If anIO (an IO like object or an object that responds to the write method) was given, the resulting PSON is written to it.
If the number of nested arrays or objects exceeds limit an ArgumentError exception is raised. This argument is similar (but not exactly the same!) to the limit argument in Marshal.dump.
This method is part of the implementation of the load/dump interface of Marshal and YAML.
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
# File 'lib/puppet/external/pson/common.rb', line 294 def dump(obj, anIO = nil, limit = nil) if anIO and limit.nil? anIO = anIO.to_io if anIO.respond_to?(:to_io) unless anIO.respond_to?(:write) limit = anIO anIO = nil end end limit ||= 0 result = generate(obj, :allow_nan => true, :max_nesting => limit) if anIO anIO.write result anIO else result end rescue PSON::NestingError raise ArgumentError, _("exceed depth limit"), $!.backtrace end |