Forum: Ruby inlining yaml

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Dan K. (Guest)
on 2007-01-19 17:29
(Received via mailing list)
I want to be able to inline certain parts of yaml output that are
embedded within a structure.  Here's the approach I'm taking -- does
it look reasonable?  Can anyone recommend a better approach?   -dan

require 'yaml'
class Object
  def inline!
    class << self; def to_yaml_style; :inline; end; end
    self
  end
end

ary = %w[a b c]
ary.inline!
other = %w[a b c]

puts ({ 'ary' => ary, 'other' => other }).to_yaml
---
ary: [a, b, c]
other:
- a
- b
- c
This topic is locked and can not be replied to.