Module: Sequel::SQL::PatternMatchMethods

Included in:
ComplexExpression, GenericExpression
Defined in:
lib/sequel/sql.rb

Overview

This module includes methods for overriding the =~ method for SQL equality, inclusion, and pattern matching. It returns the same result that Sequel would return when using a hash with a single entry, where the receiver was the key and the argument was the value. Example:

Sequel.expr(:a) =~ 1 # (a = 1)
Sequel.expr(:a) =~ [1, 2] # (a IN [1, 2])
Sequel.expr(:a) =~ nil # (a IS NULL)

On Ruby 1.9+, this also adds the !~ method, for easily setting up not equals, exclusion, and inverse pattern matching. This is the same as as inverting the result of the =~ method

Sequel.expr(:a) !~ 1 # (a != 1)
Sequel.expr(:a) !~ [1, 2] # (a NOT IN [1, 2])
Sequel.expr(:a) !~ nil # (a IS NOT NULL)

Instance Method Summary collapse

Instance Method Details

#=~(other) ⇒ Object

Set up an equality, inclusion, or pattern match operation, based on the type of the argument.



813
814
815
# File 'lib/sequel/sql.rb', line 813

def =~(other)
  BooleanExpression.send(:from_value_pair, self, other)
end