https://github.com/theodorton/ruby-string-calculate
Extension of Ruby's String class to calculate simple mathematic expressions
https://github.com/theodorton/ruby-string-calculate
Last synced: about 1 month ago
JSON representation
Extension of Ruby's String class to calculate simple mathematic expressions
- Host: GitHub
- URL: https://github.com/theodorton/ruby-string-calculate
- Owner: theodorton
- Created: 2011-09-12T09:46:17.000Z (almost 15 years ago)
- Default Branch: master
- Last Pushed: 2015-09-08T05:41:22.000Z (almost 11 years ago)
- Last Synced: 2025-02-25T22:46:51.430Z (over 1 year ago)
- Language: Ruby
- Size: 138 KB
- Stars: 3
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Calculator extension for the Ruby Strings #
Adds a method `calculate` to the Ruby String-class.
The method can do the following mathematical operations:
* Addition
* Subtraction
* Multiplication
* Division
### Examples: ###
"1 + 2".calculate # => 3
"9 - 2".calculate # => 7
"5 * 2".calculate # => 10
"15 / 3".calculate # => 5
## Advanced expressions ##
It also handles more advanced expressions with operations done in the following order:
1. Multiplication
2. Division
3. Subtraction
4. Addition
### Examples: ###
"15+35-5*5".calculate # => 25
"5+10/2-8*4".calculate # => -22
"16*12/6+67-12+20/5".calculate # => 91