Class: Regaxp::Eiruc
- Inherits:
-
Object
- Object
- Regaxp::Eiruc
- Defined in:
- lib/regaxp/eiruc.rb
Overview
Parses and execute Reverse Polish notation expressions.
Defined Under Namespace
Classes: UndefinedFun
Instance Method Summary collapse
- #evaluate(expression) ⇒ Object
- #fun(name, fun_object = nil, &fun_body) ⇒ Object
-
#initialize ⇒ Eiruc
constructor
A new instance of Eiruc.
Constructor Details
#initialize ⇒ Eiruc
Returns a new instance of Eiruc.
10 11 12 |
# File 'lib/regaxp/eiruc.rb', line 10 def initialize @functions = {} end |
Instance Method Details
#evaluate(expression) ⇒ Object
14 15 16 |
# File 'lib/regaxp/eiruc.rb', line 14 def evaluate(expression) expression.reduce([]) { |stack, token| process_token token, stack }[0] end |
#fun(name, fun_object = nil, &fun_body) ⇒ Object
18 19 20 21 22 |
# File 'lib/regaxp/eiruc.rb', line 18 def fun(name, fun_object = nil, &fun_body) # TODO: validates fun_object is a callable # TODO: validates arity? functions[name.to_sym] = fun_body || fun_object end |