Created
March 5, 2013 22:53
-
-
Save jumanjiman/5095103 to your computer and use it in GitHub Desktop.
trivial demo to save timestamp in a file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'date' | |
require 'yaml' | |
now = DateTime.now | |
puts 'time is now %s' % now | |
my_hash = Hash.new | |
my_hash['last_update'] = now.iso8601 | |
path = '/tmp/boogabooga.yaml' | |
# save my time | |
File.open(path, 'w') do |f| | |
f.puts my_hash.to_yaml | |
end | |
# sleep 5 seconds | |
5.times {print '.'; sleep 1} | |
puts '' | |
# read it back | |
y = YAML.load_file(path) | |
puts 'time is now %s' % DateTime.now.iso8601 | |
puts 'but last update was %s' % y['last_update'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment