Class: Gloo::Core::Op

Inherits:
Object
  • Object
show all
Defined in:
lib/gloo/core/op.rb

Direct Known Subclasses

Expr::OpDiv, Expr::OpMinus, Expr::OpMult, Expr::OpPlus

Class Method Summary collapse

Class Method Details

.create_op(token) ⇒ Object

Create the operator for the given token.



22
23
24
25
26
27
28
29
# File 'lib/gloo/core/op.rb', line 22

def self.create_op( token )
  return Gloo::Expr::OpMinus.new if token == '-'
  return Gloo::Expr::OpMult.new if token == '*'
  return Gloo::Expr::OpDiv.new if token == '/'
  return Gloo::Expr::OpPlus.new if token == '+'

  return default_op
end

.default_opObject

Get the default operator (+).



34
35
36
# File 'lib/gloo/core/op.rb', line 34

def self.default_op
  return Gloo::Expr::OpPlus.new
end

.op?(token) ⇒ Boolean

Is the token an operator?

Returns:

  • (Boolean)


15
16
17
# File 'lib/gloo/core/op.rb', line 15

def self.op?( token )
  return [ '+', '-', '*', '/' ].include?( token.strip )
end