Skip to content

Instantly share code, notes, and snippets.

@havenwood
Created November 12, 2019 22:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save havenwood/40eb7293d6794dc3cc317bbfb55dea7b to your computer and use it in GitHub Desktop.
Save havenwood/40eb7293d6794dc3cc317bbfb55dea7b to your computer and use it in GitHub Desktop.
Example YAML template for Net on #ruby channel IRC
require 'erb'
require 'psych'
topic = :users
users = %w[wombat fox poodle]
template = ERB.new <<~END, trim_mode: '-'
---
:<%= topic %>:
<%- users.each do |user| %>
- <%= user %>
<%- end %>
END
yaml = template.result binding
#=> "---\n:users:\n\n- wombat\n\n- fox\n\n- poodle\n\n"
Psych.safe_load(yaml, permitted_classes: [Symbol])
#=> {:users=>["wombat", "fox", "poodle"]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment