Class: Panda::Comparison

Inherits:
Expression show all
Defined in:
lib/panda/expressions.rb

Overview

The binary comparison expression node class.

Comparison expressions consist of a Panda::Subject object as the left operand (the ‘subject’ of a comparison) and any type of object as the right operand (the ‘object’ of a comparison).

The possible operators are:

  • :== (is)

  • :not

  • :< (less_than)

  • :<= (less_than_or_equal_to)

  • :> (greater_than)

  • :>= (greater_than_or_equal_to)

  • :=~ (matches_regexp)

  • :like

  • :ilike

NOTE:

It is not possible in ruby 1.8 to overload the != operator so you’ll have to call it by name (:not) :P.

Instance Attribute Summary

Attributes inherited from Expression

#left, #operator, #right

Instance Method Summary collapse

Methods inherited from Expression

#has_operator?, has_operator?, #inspect, inspector=, #operator_alias, operator_alias_for, operators

Methods inherited from Node

define_operator_builders_for

Constructor Details

#initialize(subject, operator, object) ⇒ Comparison

Same precondition as Panda::Expression plus a Panda::SyntaxError is raised if subject is not an instance of Panda::Subject.



177
178
179
180
181
182
# File 'lib/panda/expressions.rb', line 177

def initialize(subject, operator, object)
  unless subject.kind_of?(Subject)
    raise SyntaxError, "Bad subject for #{self.class}: expected an instance of Panda::Subject but got #{subject.inspect}"
  end
  super
end