1

A simple example for illustration, this is not actually what I'm trying to do:

I have two scopes on a user model:

scope :unarchived, -> { where archived: false }
scope :active, -> { where active: true }

For convenience and dryness, I want a scope called :awake that is the combination of User.unarchived.active written in the stabby lambda notation. NOTE, I know I can write something like this:

def self.awake
  self.unarchived.active
end

I would like to know if and how this is possible inside a lambda scope definition and if not, I would appreciate an explanation or a link as to why it isn't.

Ekkstein
  • 771
  • 11
  • 20

1 Answers1

1

I just realised, it is straight forward. I just needed to notice, that inside the lambda is an expression, that returns a query/criteria object. simply writing:

scope :awake, -> { self.unarchived.active }

or even simpler as mentioned below:

scope :awake, -> { unarchived.active }

does the trick.

Ekkstein
  • 771
  • 11
  • 20