Last active
January 12, 2017 18:11
Star
You must be signed in to star a gist
Ruby: Parse yaml without converting time-strings to objects
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 '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