Created
June 2, 2013 09:50
-
-
Save sferik/5693188 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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