Skip to content

Instantly share code, notes, and snippets.

@malakai97
Last active January 12, 2017 18:11
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save malakai97/aea8c6dcae696c4c486a1e793d56b1d8 to your computer and use it in GitHub Desktop.
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