Skip to content

Instantly share code, notes, and snippets.

@chapados
Created September 30, 2008 19:36
Show Gist options
  • Save chapados/13926 to your computer and use it in GitHub Desktop.
Save chapados/13926 to your computer and use it in GitHub Desktop.
require 'date'
requrie 'yaml'
class DateTime
yaml_as "tag:ruby.yaml.org,2002:datetime"
def DateTime.yaml_new(klass, tag, val)
if String === val
self.parse(val)
else
raise YAML::TypeError, "Invalid DateTime: " + val.inspect
end
end
def to_yaml( opts = {} )
YAML::quick_emit( object_id, opts ) do |out|
out.scalar( taguri, self.to_s, :plain )
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment