From: "Jesús Gabriel y Galán" Date: 2013-07-27T20:59:02+09:00 Subject: Re: Calculate input - numbers On Sat, Jul 27, 2013 at 1:44 PM, Marc Heiler wrote: > Hi > > user_input = $stdin.gets.chomp > > Now the user types: > > "5 + 5" > > As string (without the quotes). > > user_input is now a string object containing "5 + 5" > > I would like to give back the result of the operation, which should be > 10. > > Right now I use eval() and it works, but I am wondering if there is a > better alternative for it? How does IRB solve this? IRB uses eval too. You can see it here: https://github.com/ruby/ruby/blob/trunk/lib/irb/workspace.rb#L85 Jesus.