Monday, December 13, 2004

How Many Days Ago in Ruby

So Weiqi wondered How Many Days Ago was that. Then Eric posted a Java solution.

Since I have been attempting to learn Ruby, I figured I would attempt to implement a solution in Ruby. I would like to preface this post by stating that I am a Ruby novice and I'm sure there is a better way to do this. Here's the "How Many Days Ago Was That" in Ruby.



require "parsedate"
require "date"

def usage()
puts "Usage: daysago.rb date"
exit 1
end

def computeDaysBetween(from, to)
from, to = to, from if (from > to) # Swaps the two variables
daysAgo = 0
from.upto(to) {|day|daysAgo+=1}
return daysAgo
end

from = Date.parse(ARGV.shift || usage())
puts "It has been #{computeDaysBetween(from, Date.today)} since #{from}"


Thursday, December 09, 2004

Tapestry Presentation from St. Louis JUG

I presented on Tapestry tonight at the St. Louis Java Users Group. Here's a link to the presentation in pdf format.