1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/lib/arel/math.rb
Shahbaz Javeed c22abda79b * Support for bitwise operations as infix operators. Tests included.
*** Individual commit messages included below ***
* Preliminary support for bitwise operations as infix operators.  Tests to follow.

* Added bitwise xor, shift left and shift right operators

* Fixed the BitwiseOr class so it uses the :| operator instead of :&
* All the methods for the bitwise operators in the Arel::Math module now wrap them up in Arel::Nodes::Grouping so the operation becomes isolated like addition and subtraction
* Preliminary set of tests for the new operators

* Updated README with examples of bitwise operations

* Added a new UnaryOperation class which is a riff on the InfixOperation class
* Added tests for UnaryOperation (inspired by InfixOperation tests)
* Added the bitwise not (~) operator as a UnaryOperation
* Added tests for the bitwise not operator

* Added documentation for the bitwise not operator

* Updated gemspec using `rake arel.gemspec`
2016-01-06 11:18:42 -05:00

43 lines
956 B
Ruby

module Arel
module Math
def *(other)
Arel::Nodes::Multiplication.new(self, other)
end
def +(other)
Arel::Nodes::Grouping.new(Arel::Nodes::Addition.new(self, other))
end
def -(other)
Arel::Nodes::Grouping.new(Arel::Nodes::Subtraction.new(self, other))
end
def /(other)
Arel::Nodes::Division.new(self, other)
end
def &(other)
Arel::Nodes::Grouping.new(Arel::Nodes::BitwiseAnd.new(self, other))
end
def |(other)
Arel::Nodes::Grouping.new(Arel::Nodes::BitwiseOr.new(self, other))
end
def ^(other)
Arel::Nodes::Grouping.new(Arel::Nodes::BitwiseXor.new(self, other))
end
def <<(other)
Arel::Nodes::Grouping.new(Arel::Nodes::BitwiseShiftLeft.new(self, other))
end
def >>(other)
Arel::Nodes::Grouping.new(Arel::Nodes::BitwiseShiftRight.new(self, other))
end
def ~@
Arel::Nodes::BitwiseNot.new(self)
end
end
end