radar/forem — comment on commit 326327a9b4e6c76a783f5df22c6972d6ccedb836
File:  line 0
By radar:

Not so much documentation, but rather people just *suggesting* that they're bad idea and offering some very similar arguments.

The problem with scopes is most obvious if you write one that uses times or dates, like this:

```ruby
scope :one_week_ago, where("created_at > ?", 1.week.ago)
```

That `1.week.ago` call is going to be evaluated as soon as the model is loaded. In production, a model *could* stay loaded for a very long time, and so this count is going to be off.

You can fix this in two ways. The first is wrapping it in a lambda:

```ruby
scope :one_week_ago, lambda { where("created_at > ?", 1.week.ago) }
```

I think this just makes it ugly. The second way to fix this is to define it as a class method:

```ruby
def self.one_week_ago
where("created_at > ?", 1.week.ago)
end
```

That way, the method is re-evaluated every time that it's called, rather than when the model is loaded.