public
Created

  • Download Gist
test.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
require 'psych'
 
list = ('a'..'z').to_a
 
# Create a YAML AST
viz = Psych::Visitors::YAMLTree.new {}
viz << list
tree = viz.tree
 
# Change the Sequence node to be FLOW style
tree.children.first.children.first.style = Psych::Nodes::Sequence::FLOW
 
# Output as YAML
puts tree.to_yaml
 
 
# Or just use JSON style (it defaults to flow)
puts Psych.to_json list

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.