Today I Learned

hashrocket A Hashrocket project

Ruby objects from YAML

For certain objects if the ISO8601 standard is followed, Ruby will create an instance instead of a string when parsing the value.

"A date can be represented by its year, month and day in ISO8601 order."

For example:

post.txt

title: Updated
date: 2011-09-25
pry(main)> p = YAML.load(File.new('post.txt'))
=> {"title"=>"Updated", "date"=>#<Date: 2011-09-25 ((2455830j,0s,0n),+0s,2299161j)>}
pry(main)> p['date'].class
=> Date

http://yaml.org/YAML_for_ruby.html#date

See More #ruby TILs
Looking for help? Each developer at Hashrocket has years of experience working with Ruby applications of all types and sizes. We're an active presence at Ruby conferences, have written some of the most popular gems, and have worked on many of the web's Ruby on Rails success stories. Contact us today to talk about your Ruby project.