Yaml and dates

It’s turning out to be very difficult to come up with a reliable
example, but I’m having problems with dates in yaml. Sometimes they
turn up in Ruby as dates, sometimes as strings.

Is anyone else having this problem?

This might be it. Understandable but annoying:

irb(main):001:0> require ‘date’
=> true
irb(main):004:0> require ‘yaml’
=> true
irb(main):010:0> a = “2008-08-10”
=> “2008-08-10”
irb(main):011:0> y = YAML::load(a)
=> #<Date: 4909377/2,0,2299161>
irb(main):012:0> a = “2008-8-10”
=> “2008-8-10”
irb(main):013:0> y = YAML::load(a)
=> “2008-8-10”

Annoying because Date.parse(“2008-8-10”) would be fine.

Can anyone suggest an elegant way to upgrade YAML::load()?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs