Fixed up the Ruby implementation a bit

Code is a bit more idiomatic Ruby.
I've also turned it ino a gem.