Class: GlooLang::Core::Op

Inherits:
Object
  • Object
show all
Defined in:
lib/gloo_lang/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_lang/core/op.rb', line 22

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

  return default_op
end

.default_opObject

Get the default operator (+).



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

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

.op?(token) ⇒ Boolean

Is the token an operator?

Returns:

  • (Boolean)


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

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