views:

124

answers:

1
+2  Q: 

Ruby YAML::load

I'm trying to modify the default deserialization of the built-in timestamp format, to affect Ruby's Time.

I do this (successfully) with Hash:

YAML::add_domain_type('yaml.org,2002', 'map') { |t, v| nil }
YAML::add_domain_type('ruby.yaml.org,2002', 'hash') { |t, v| nil }
hash = { :hello => :world }
puts YAML::load(hash.to_yaml) # nil

But when I try the same with Time, it doesn't work:

YAML::add_domain_type('yaml.org,2002', 'timestamp') { |t, v| nil }
YAML::add_domain_type('ruby.yaml.org,2002', 'time') { |t, v| nil }
puts YAML::load(Time.now.to_yaml).class # 'Time'

Any help would be appreciated. Thanks!

A: 

what is the purpose of the very first line,

YAML::add_domain_type('yaml.org,2002', 'map') { |t, v| nil }

because if you remove that, the hash doesn't work either.

stephenr