Last active
January 12, 2017 18:11
-
-
Save malakai97/aea8c6dcae696c4c486a1e793d56b1d8 to your computer and use it in GitHub Desktop.
Ruby: Parse yaml without converting time-strings to objects
This file contains hidden or 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