Class: Calculator::Token
- Inherits:
-
Object
- Object
- Calculator::Token
- Defined in:
- lib/linmeric/Calculator.rb
Overview
Definition of a simple token with an attribute (@tag) and a value (@val)
- Author
-
Massimiliano Dal Mas ([email protected])
- License
-
Distributed under MIT license
Instance Method Summary collapse
-
#initialize(value) ⇒ Token
constructor
-
argument: value to tokenize (String).
-
-
#tag ⇒ Object
-
returns: tag of the token.
-
-
#value ⇒ Object
-
returns: value of the token.
-
Constructor Details
#initialize(value) ⇒ Token
-
argument: value to tokenize (String)
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/linmeric/Calculator.rb', line 25 def initialize(value) @val = value if OP.include? value then @tag = :OPERATOR elsif value.number? then @tag = :NUMBER @val = value.to_n elsif value == "(" then @tag = :L_PAR elsif value == ")" then @tag = :R_PAR end end |
Instance Method Details
#tag ⇒ Object
-
returns: tag of the token
45 46 47 |
# File 'lib/linmeric/Calculator.rb', line 45 def tag return @tag end |
#value ⇒ Object
-
returns: value of the token
40 41 42 |
# File 'lib/linmeric/Calculator.rb', line 40 def value return @val end |