Skip to content

Instantly share code, notes, and snippets.

@sferik
Created June 2, 2013 09:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sferik/5693188 to your computer and use it in GitHub Desktop.
Save sferik/5693188 to your computer and use it in GitHub Desktop.
a = 1 # one
b = a - 1 # zero
(b..a).include?(a) #=> true
(b..a).include?(a.to_f) #=> true
(b..a).include?(0.5) #=> true
a = DateTime.now # now
b = a - 1 # 24 hours ago
(b..a).include?(a) #=> true
(b..a).include?(a.to_date) #=> false
(b..a).cover?(a.to_date) #=> true
(b..a).include?(a.to_time) #=> false
(b..a).cover?(a.to_time) #=> false
a = Date.today # today
b = a - 1 # yesterday
(b..a).include?(a) #=> true
(b..a).include?(a.to_datetime) #=> true
(b..a).include?(a.to_time) #=> false (in the Western Hemisphere)
a = Time.now # now
b = a - 1 # a second ago
(b..a).include?(a) # TypeError: can't iterate from Time
(b..a).cover?(a) #=> true
(b..a).cover?(a.to_datetime) #=> false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment