Created
November 12, 2019 22:51
-
-
Save havenwood/40eb7293d6794dc3cc317bbfb55dea7b to your computer and use it in GitHub Desktop.
Example YAML template for Net on #ruby channel IRC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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