Class: Time
- Inherits:
-
Object
- Object
- Time
- Defined in:
- lib/time/time-ago-in-words.rb
Defined Under Namespace
Modules: Units
Instance Method Summary collapse
Instance Method Details
#time_ago_in_words ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/time/time-ago-in-words.rb', line 16 def time_ago_in_words time_difference = Time.now.to_i - self.to_i unit = get_unit(time_difference) unit_difference = time_difference / Units.const_get(unit.capitalize) unit = unit.to_s.downcase + ('s' if time_difference > 1) "#{unit_difference} #{unit} ago" end |