Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 3 days 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 (over 13 years ago)
- Default Branch: master
- Last Pushed: 2015-09-08T05:41:22.000Z (over 9 years ago)
- Last Synced: 2024-12-26T03:24:02.220Z (17 days 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