Class: ActiveRecord::Refined::AST::Arithmetic
- Includes:
- Arithmetics, Predications
- Defined in:
- lib/active_record/refined/ast.rb
Overview
Arithmetic on columns and expressions. Ruby's precedence puts these above the comparison operators, so :price * :quantity > 100 groups the way it reads.
Instance Attribute Summary collapse
-
#left ⇒ Object
readonly
Returns the value of attribute left.
-
#operator ⇒ Object
readonly
Returns the value of attribute operator.
-
#right ⇒ Object
readonly
Returns the value of attribute right.
Instance Method Summary collapse
-
#initialize(left, operator, right) ⇒ Arithmetic
constructor
A new instance of Arithmetic.
- #to_arel(table, model) ⇒ Object
Methods included from Arithmetics
#&, #*, #+, #-, #/, #<<, #>>, #^, #|, #~
Methods included from Predications
#!=, #!~, #<, #<=, #==, #=~, #>, #>=, #between?, #bury, #casecmp?, #contains?, #dig, #dig_text, #distinct_from?, #end_with?, #except, #false?, #ilike?, #in?, #include?, #intersect?, #key?, #keys, #like?, #member?, #not_between?, #not_distinct_from?, #not_false?, #not_ilike?, #not_in?, #not_like?, #not_null?, #not_true?, #null?, #start_with?, #subset?, #superset?, #true?, #when
Methods inherited from Node
Constructor Details
#initialize(left, operator, right) ⇒ Arithmetic
Returns a new instance of Arithmetic.
1265 1266 1267 1268 1269 |
# File 'lib/active_record/refined/ast.rb', line 1265 def initialize(left, operator, right) @left = left @operator = operator @right = right end |
Instance Attribute Details
#left ⇒ Object (readonly)
Returns the value of attribute left.
1263 1264 1265 |
# File 'lib/active_record/refined/ast.rb', line 1263 def left @left end |
#operator ⇒ Object (readonly)
Returns the value of attribute operator.
1263 1264 1265 |
# File 'lib/active_record/refined/ast.rb', line 1263 def operator @operator end |
#right ⇒ Object (readonly)
Returns the value of attribute right.
1263 1264 1265 |
# File 'lib/active_record/refined/ast.rb', line 1263 def right @right end |
Instance Method Details
#to_arel(table, model) ⇒ Object
1271 1272 1273 1274 1275 1276 1277 |
# File 'lib/active_record/refined/ast.rb', line 1271 def to_arel(table, model) arel_left = to_arel_operand(left, table, model) # The operator dispatches Arel's Math, which a bare number carries # none of; quoted, it is a node with the same methods. arel_left = Arel::Nodes.build_quoted(arel_left) if arel_left.is_a?(::Numeric) arel_left.public_send(operator, to_arel_operand(right, table, model)) end |