Class: Cyrel::Expression::Operator
- Defined in:
- lib/cyrel/expression/operator.rb
Overview
Represents a binary arithmetic operation (e.g., +, -, *, /, %, ^).
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) ⇒ Operator
constructor
A new instance of Operator.
-
#render(query) ⇒ String
Renders the operator expression.
Methods inherited from Base
#!=, #%, #&, #*, #+, #-, #/, #<, #<=, #==, #=~, #>, #>=, #^, #|
Constructor Details
#initialize(left, operator, right) ⇒ Operator
Returns a new instance of Operator.
12 13 14 15 16 |
# File 'lib/cyrel/expression/operator.rb', line 12 def initialize(left, operator, right) @left = Expression.coerce(left) # Ensure operands are Expression objects @operator = operator @right = Expression.coerce(right) end |
Instance Attribute Details
#left ⇒ Object (readonly)
Returns the value of attribute left.
7 8 9 |
# File 'lib/cyrel/expression/operator.rb', line 7 def left @left end |
#operator ⇒ Object (readonly)
Returns the value of attribute operator.
7 8 9 |
# File 'lib/cyrel/expression/operator.rb', line 7 def operator @operator end |
#right ⇒ Object (readonly)
Returns the value of attribute right.
7 8 9 |
# File 'lib/cyrel/expression/operator.rb', line 7 def right @right end |
Instance Method Details
#render(query) ⇒ String
Renders the operator expression.
21 22 23 24 |
# File 'lib/cyrel/expression/operator.rb', line 21 def render(query) # Parentheses ensure correct precedence "(#{@left.render(query)} #{@operator} #{@right.render(query)})" end |