minad-evaluator 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/evaluator.rb +3 -4
- metadata +1 -1
data/lib/evaluator.rb
CHANGED
@@ -4,7 +4,7 @@ module Evaluator
|
|
4
4
|
def self.infix(priority, unary = nil, &block) [false, priority, lambda(&block), unary] end
|
5
5
|
def self.prefix(&block) [true, 1e5, lambda(&block)] end
|
6
6
|
|
7
|
-
VERSION = "0.1.
|
7
|
+
VERSION = "0.1.3"
|
8
8
|
OPERATOR = {
|
9
9
|
'||' => infix(0) {|a,b| a || b },
|
10
10
|
'&&' => infix(1) {|a,b| a && b },
|
@@ -104,7 +104,7 @@ module Evaluator
|
|
104
104
|
def self.eval(expr, vars = {})
|
105
105
|
vars = Hash[*vars.map {|k,v| [k.to_s.downcase, v] }.flatten].merge(CONSTANTS)
|
106
106
|
stack, result, unary = [], [], true
|
107
|
-
expr.scan(TOKENIZER).each do |tok|
|
107
|
+
expr.to_s.scan(TOKENIZER).each do |tok|
|
108
108
|
if tok == '('
|
109
109
|
stack << '('
|
110
110
|
elsif tok == ')'
|
@@ -141,8 +141,7 @@ module Evaluator
|
|
141
141
|
unary = true
|
142
142
|
end
|
143
143
|
exec(result, stack.pop) while !stack.empty?
|
144
|
-
|
145
|
-
result[0]
|
144
|
+
result.last
|
146
145
|
end
|
147
146
|
|
148
147
|
def self.exec(result, op)
|