Skip to content

Instantly share code, notes, and snippets.

@b-coimbra
Created July 26, 2017 14:11
Show Gist options
  • Save b-coimbra/2c704003a62b44fc71fe1e3793b6dc30 to your computer and use it in GitHub Desktop.
Save b-coimbra/2c704003a62b44fc71fe1e3793b6dc30 to your computer and use it in GitHub Desktop.
define_method(:calc) { |c| return eval(c.gsub(/\[/,"(").gsub(/\]/,")").gsub(/(modulus|mod)/i,"%").gsub(/(subtract|minus)/i,"-").gsub(/(add|plus)/i,"+").gsub(/(\^|power by)/i,"**").gsub(/(×|∙|multiplied by)/i,"*").gsub(/(divided by|÷)/i,"/").gsub(/[^0-9\s\-\(\)^*+\/]/,"")) rescue return false }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment