Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Ruby: Parse yaml without converting time-strings to objects
require 'psych'
class WorseScanner < Psych::ScalarScanner
def parse_time(s)
s
end
end
s = "---\nf: 2001-02-29T01:02:03-03:00" # Note this day doesn't exist.
ast = Psych.parse(s)
class_loader = Psych::ClassLoader.new
visitor = Psych::Visitors::ToRuby.new(WorseScanner.new(class_loader), class_loader)
result = visitor.accept(ast)
puts result
----
$ ruby yaml_parse_no_times.rb
{"f"=>"2001-02-29T01:02:03-03:00"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.