# Implementing a "calcuator" feature

**URL:** <https://www.ruby-forum.com/t/implementing-a-calcuator-feature/82789>\
**Category:** Ruby\
**Created:** [January 21, 2007, 1:42am UTC](https://www.ruby-forum.com/t/implementing-a-calcuator-feature/82789 "2007-01-21T01:42:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![soroe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f9ae1b/32.png) [@soroe](https://www.ruby-forum.com/u/soroe)\
**Post date:** [January 21, 2007, 1:42am UTC](https://www.ruby-forum.com/t/implementing-a-calcuator-feature/82789/1 "2007-01-21T01:42:36Z")

</div>

Hey Guys,

Can someone recommend a fast but robust way to implement a calculator  
feature? I want to allow my users the ability to enter simple agebraic  
expressions and then press ‘calc’.

My initial thought was to:

1. Check the expression for “bad words” and escapes by checking against  
a black list.

2. Any expressions that pass step 1 are then evaluated with ‘eval’.

Anyone have better ideas? In terms of the black list, does anyone know  
how I can load the list of ruby reserved words without having to  
actually type them all in by hand?

Soroe.

---

<div class="post-metadata">

**Author:** ![soroe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f9ae1b/32.png) [@soroe](https://www.ruby-forum.com/u/soroe)\
**Post date:** [January 21, 2007, 1:58am UTC](https://www.ruby-forum.com/t/implementing-a-calcuator-feature/82789/2 "2007-01-21T01:58:54Z")

</div>

On 20-Jan-07, at 7:42 PM, Sonny C. wrote:

> a black list.
> 
> 1. Any expressions that pass step 1 are then evaluated with ‘eval’.
> 
> Anyone have better ideas? In terms of the black list, does anyone  
> know  
> how I can load the list of ruby reserved words without having to  
> actually type them all in by hand?

Why not just write a parser for algebraic expressions?
