First, install it:
gem install tagoHere is how you use it:
start = Time.now
# something long
puts "It took #{start.ago} to do it"It's also possible to convert Float seconds to text:
s = Time.now - start
puts "It took #{s.seconds}"The seconds method accepts optional formatting flags:
9.444.seconds # => "9s444ms"
9.444.seconds(:round) # => "9s" (omits sub-units)
9.444.seconds(:short) # => "9s" (also omits sub-units)
300.0.seconds(:pretty) # => "five minutes" (words instead of abbreviations)
300.0.seconds(:pretty, :short) # => "5 min" (numeric with short unit names)
5.0.seconds(:pretty, :caps) # => "Five seconds" (capitalizes first letter)The same flags work with ago:
start.ago(:round)
start.ago(:pretty)
start.ago(:pretty, :short)
start.ago(:pretty, :caps)
start.ago(Time.now, :round)The gem basically extends the Float and Time classes with new methods.
Read these guidelines. Make sure your build is green before you contribute your pull request. You will need to have Ruby 3.2+ and Bundler installed. Then:
bundle update
bundle exec rakeIf it's clean and you don't see any error messages, submit your pull request.