You are right, each of them returns ActiveRecord::Relation . Each method call is built on the relation on which it was called (with the exception of the first, which, obviously, has nothing to build on, since it was not called on the relation) and returns this.
He “knows” where the end of the chain is that the request is not actually executed until you try to manipulate / access the data, and (usually implicitly) is called to_a , which runs exec_queries .
Andrew Marshall
source share