Skip to content

Instantly share code, notes, and snippets.

@nottombrown
Created August 12, 2013 22:13
Show Gist options
  • Save nottombrown/6215824 to your computer and use it in GitHub Desktop.
Save nottombrown/6215824 to your computer and use it in GitHub Desktop.
def e(s, v=[:+, :-, :*, :/])v.empty? ? s.to_i : s.split(v[0].to_s).map{|y| e(y, v[1..-1])}.reduce(v[0])end
p e('2') # 2
p e('2 * 12') # 24
p e('1-10+4*2') # -1
p e('1+50/2*3') # 76
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment