Skip to content

Instantly share code, notes, and snippets.

@tenderlove
Created July 29, 2011 17:21
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tenderlove/1114256 to your computer and use it in GitHub Desktop.
Save tenderlove/1114256 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment