Module: ActiveRecord::Refined::AST::Arithmetics
- Included in:
- Aggregate, Arithmetic, Bitwise, BitwiseNot, Case, Cast, Column, DatetimeValueFunction, Extract, Function, JsonPath, Operation, Over, Sql, Value, BlockSyntax
- Defined in:
- lib/active_record/refined/ast.rb
Overview
The arithmetic and the bitwise operators on a column or an
expression. Ruby puts all of them above the comparisons, so
:price * :quantity > 100 groups the way it reads, and a number on
the left -- 20 - :quantity -- builds the same expression.
Arithmetic builders shared by symbols, qualified columns and expressions. Imported into the Symbol refinement like Predications, so every method must be defined with def.
Instance Method Summary collapse
-
#&(other) ⇒ AST::Bitwise
Bitwise AND.
-
#*(other) ⇒ AST::Arithmetic
*. -
#+(other) ⇒ AST::Arithmetic
+; with an Active Support duration on the right, a date moved::due_on + 3.days. -
#-(other) ⇒ AST::Arithmetic
-; with a duration on the right, a date moved back. -
#/(other) ⇒ AST::Arithmetic
/. -
#<<(other) ⇒ AST::Bitwise
A shift left.
-
#>>(other) ⇒ AST::Bitwise
A shift right.
-
#^(other) ⇒ AST::Bitwise
Bitwise XOR:
#on PostgreSQL,^on MySQL, and the two operations it is made of on SQLite. -
#|(other) ⇒ AST::Bitwise
Bitwise OR.
-
#~ ⇒ AST::BitwiseNot
Bitwise NOT.
Instance Method Details
#&(other) ⇒ AST::Bitwise
Bitwise AND. & between two conditions is AND, which leaves this free to mean the SQL operator.
SQL's bitwise operators. & and | are AND and OR between conditions
and are defined there, which is what leaves them free to mean here
what SQL means by them. Ruby's precedence puts all six above the
comparisons, so :flags & 4 > 0 groups the way it reads.
466 467 468 |
# File 'lib/active_record/refined/ast.rb', line 466 def &(other) Bitwise.new(self, :&, other) end |
#*(other) ⇒ AST::Arithmetic
*.
449 450 451 |
# File 'lib/active_record/refined/ast.rb', line 449 def *(other) Arithmetic.new(self, :*, other) end |
#+(other) ⇒ AST::Arithmetic
+; with an Active Support duration on the right, a date moved: :due_on + 3.days.
437 438 439 |
# File 'lib/active_record/refined/ast.rb', line 437 def +(other) Arithmetic.new(self, :+, other) end |
#-(other) ⇒ AST::Arithmetic
-; with a duration on the right, a date moved back.
443 444 445 |
# File 'lib/active_record/refined/ast.rb', line 443 def -(other) Arithmetic.new(self, :-, other) end |
#/(other) ⇒ AST::Arithmetic
/.
455 456 457 |
# File 'lib/active_record/refined/ast.rb', line 455 def /(other) Arithmetic.new(self, :/, other) end |
#<<(other) ⇒ AST::Bitwise
A shift left.
484 485 486 |
# File 'lib/active_record/refined/ast.rb', line 484 def <<(other) Bitwise.new(self, :<<, other) end |
#>>(other) ⇒ AST::Bitwise
A shift right.
490 491 492 |
# File 'lib/active_record/refined/ast.rb', line 490 def >>(other) Bitwise.new(self, :>>, other) end |
#^(other) ⇒ AST::Bitwise
Bitwise XOR: # on PostgreSQL, ^ on MySQL, and the two operations it is made of on SQLite.
478 479 480 |
# File 'lib/active_record/refined/ast.rb', line 478 def ^(other) Bitwise.new(self, :^, other) end |
#|(other) ⇒ AST::Bitwise
Bitwise OR.
472 473 474 |
# File 'lib/active_record/refined/ast.rb', line 472 def |(other) Bitwise.new(self, :|, other) end |
#~ ⇒ AST::BitwiseNot
Bitwise NOT.
496 497 498 |
# File 'lib/active_record/refined/ast.rb', line 496 def ~ BitwiseNot.new(self) end |