Class: ActiveRecord::Relation

Inherits:
Object
  • Object
show all
Defined in:
lib/rails/pattern_matching.rb

Instance Method Summary collapse

Instance Method Details

#deconstructObject

Provides the pattern matching interface for matching against array patterns. For example:

class Person < ActiveRecord::Base
end

case Person.all
in []
  "No one is here"
in [{ name: "Mary" }]
  "Only Mary is here"
in [_]
  "Only one person is here"
in [_, _, *]
  "More than one person is here"
end

Be wary when using this method with a large number of records, as it will load everything into memory.



93
94
95
# File 'lib/rails/pattern_matching.rb', line 93

def deconstruct
  records
end