Why this is not working for me:
class Time
# Return the time difference (as a Float) between now and a specified older Time or parse-able String.
# a = Time.now
# Time.since(a) # => 8.920116
# a.since(a) # => 0.0
# Time.since '11:30' # => 28.111561
# Time.since '9am' # => 9138.288258
def self.since(older_time)
Time.now.since(older_time)
end
def since(older_time)
self - (older_time.kind_of?(Time) ? older_time : Time.parse(older_time))
end
end
puts Time.since '9am'
Error message:
.rb:13:in
since': undefined methodparse’ for Time:Class (NoMethodError)
from TimeSince.rb:9:insince' from‘
TimeSince.rb:17:in
You’re not doing
require 'time'before it, and so theTime.parsemethod (and every other method in theTimeclass) will be unavailable.