Skip to content

Instantly share code, notes, and snippets.

@f440
Created December 21, 2011 01:53
Show Gist options
  • Save f440/1504198 to your computer and use it in GitHub Desktop.
Save f440/1504198 to your computer and use it in GitHub Desktop.
ruby's yaml parser behavior
f440@abhoth[17]:~$ irb-ruby-1.8.7-p352
no such file to load -- interactive_editor
ruby-1.8.7-p352 :001 > require 'date'
=> true
ruby-1.8.7-p352 :002 > require 'yaml'
=> true
ruby-1.8.7-p352 :003 > d = DateTime.parse("2011-12-21T03:30:01+00:00")
=> #<DateTime: 212191198201/86400,0,2299161>
ruby-1.8.7-p352 :004 > y = YAML.dump(d)
=> "--- 2011-12-21T03:30:01+00:00\n"
ruby-1.8.7-p352 :005 > x = YAML.load(y)
=> Wed Dec 21 12:30:01 +0900 2011
ruby-1.8.7-p352 :006 > x.class
=> Time
f440@abhoth[17]:~$ irb-ruby-1.9.3-p0
ruby-1.9.3-p0 :001 > require 'date'
=> false
ruby-1.9.3-p0 :002 > require 'yaml'
=> false
ruby-1.9.3-p0 :003 > d = DateTime.parse("2011-12-21T03:30:01+00:00")
=> #<DateTime: 2011-12-21T03:30:01+00:00 ((2455917j,12601s,0n),+0s,2299161j)>
ruby-1.9.3-p0 :004 > y = YAML.dump(d)
=> "--- !ruby/object:DateTime 2011-12-21 12:30:01.000000000 +09:00\n...\n"
ruby-1.9.3-p0 :005 > x = YAML.load(y)
=> #<DateTime: 2011-12-21T12:30:01+09:00 ((2455917j,12601s,0n),+32400s,2299161j)>
ruby-1.9.3-p0 :006 > x.class
=> DateTime
f440@abhoth[17]:~$ irb-ruby-1.9.3-p0
ruby-1.9.3-p0 :001 > require 'date'
=> false
ruby-1.9.3-p0 :002 > require 'yaml'
=> false
ruby-1.9.3-p0 :003 > YAML::ENGINE.yamler = 'syck'
=> "syck"
ruby-1.9.3-p0 :004 > d = DateTime.parse("2011-12-21T03:30:01+00:00")
=> #<DateTime: 2011-12-21T03:30:01+00:00 ((2455917j,12601s,0n),+0s,2299161j)>
ruby-1.9.3-p0 :005 > y = YAML.dump(d)
=> "--- 2011-12-21T03:30:01+00:00\n"
ruby-1.9.3-p0 :006 > x = YAML.load(y)
=> 2011-12-21 12:30:01 +0900
ruby-1.9.3-p0 :007 > x.class
=> Time
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment