Method: PSON.pretty_generate
- Defined in:
- lib/puppet/external/pson/common.rb
.pretty_generate(obj, opts = nil) ⇒ Object Also known as: pretty_unparse
Unparse the Ruby data structure obj into a PSON string and return it. The returned string is a prettier form of the string returned by #unparse.
The opts argument can be used to configure the generator, see the generate method for a more detailed explanation.
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/puppet/external/pson/common.rb', line 214 def pretty_generate(obj, opts = nil) state = PSON.state.new( :indent => ' ', :space => ' ', :object_nl => "\n", :array_nl => "\n", :check_circular => true ) if opts if opts.respond_to? :to_hash opts = opts.to_hash elsif opts.respond_to? :to_h opts = opts.to_h else raise TypeError, "can't convert #{opts.class} into Hash" end state.configure(opts) end obj.to_pson(state) end |