Skip to content

Instantly share code, notes, and snippets.

@SamSaffron
Created October 26, 2025 22:29
Show Gist options
  • Save SamSaffron/e48b5773236501ada6d11c916cd932b8 to your computer and use it in GitHub Desktop.
Save SamSaffron/e48b5773236501ada6d11c916cd932b8 to your computer and use it in GitHub Desktop.
yaml
#!/usr/bin/env ruby
require "psych"
require "psych/pure"
yaml_source = <<~YAML
hierarchy:
- name: "osfamily/major release"
paths:
# Comment above first item
- "path/one.yaml"
- "path/two.yaml"
# Comment above third item
- path/three.yaml
- name: "osfamily"
paths:
- "path/four.yaml"
- "path/five.yaml"
YAML
puts "=== Original YAML ==="
puts yaml_source
config =
Psych::Pure.load(
yaml_source,
comments: true,
aliases: true,
permitted_classes: [Symbol, Date, Time, Set]
)
puts "\n=== After Load + Dump ==="
dumped = Psych::Pure.dump(config)
puts dumped
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment