Meaning of two points after object (..) in method calling

Viewed 63

Whats the meaning of the two points in the following code snipped?

@collection = @collection.where(end_time: DateTime.now..) 
1 Answers

This is an endless range, first introduced in ruby version 2.6. You can see the latest documentation on the language feature here.

As with all ruby code, a good way to understand small snippets is to paste them into a REPL such as pry or irb to see the result:

DateTime.now..
  => Fri, 11 Jun 2021 14:29:09 +0000..

So in your particular case, the code:

@collection.where(end_time: DateTime.now..) 

is a fancy way of saying saying "collection where end_time >= DateTime.now". You should see this reflected in the generated SQL statement.

Related