Task/24-game/Ruby/24-game.rb
# convert expression to use rational numbers, evaluate, then return as float
convert expression to use rational numbers, evaluate, then return as float
convert expression to use rational numbers evaluate then return as float
def evaluate(guess)
  as_rat = guess.gsub(/(\d)/, 'Rational(\1,1)')
  begin
    eval "(#{as_rat}).to_f"
  rescue SyntaxError
    "[syntax error]"
  end
end
def evaluate ( guess ) as_rat = guess . gsub ( / ( \d ) / , 'Rational(\1,1)' ) begin eval "(#{as_rat}).to_f" rescue SyntaxError "[syntax error]" end end
convert expression to use rational numbers, evaluate, then return as float
convert expression to use rational numbers evaluate then return as float
guess
<not_specific>