Как мне добавить в руби-калькулятор унарные операции?

Как мне добавить в руби-калькулятор унарные операции? sqrt, sin, cos, tan, ctan, exp, ln, ! и др через

irb(main):006:0> Math.sqrt(9)

не работает, или я просто не туда вставляю.

код всей программы:

# цепной калькулятор

  while true do
  puts "Calculator has started"

  print 'Type number: '
  result = gets.strip.to_i
  print 'Type operation: '
  operation = gets.strip

  while true do
    print 'Type number: '
    second_number = gets.strip.to_i

    if operation == "+"
      result += second_number
    elsif operation == "-"
      result -= second_number
    elsif operation == "*"
      result *= second_number
    elsif operation == "/"
      result /= second_number
      elsif operation == "**"
      result **= second_number
          elsif operation == "%"
      result %= second_number
    end

    print 'Result: '
    puts result

    print 'Type operation: '
    operation = gets.strip
    break if operation == ""
  end
end

# Ячейка пам¤ти, не сбрасывается при рестарте калькул¤тора
memory = 0
while true
  puts "Calculator has started"
  print 'Type number: '
  result = gets.strip.to_i

  while true
    print 'Type operation: '
    operation = gets.strip
    break if operation == ""

    if operation == 'mw'
      memory = result
    elsif operation == 'mr'
      result = memory
    else
      print 'Type number: '
      second_number = gets.strip.to_i
    end

    if operation == "+"
      result += second_number
    elsif operation == "-"
      result -= second_number
    elsif operation == "*"
      result *= second_number
    elsif operation == "/"
      result /= second_number
      elsif operation == "**"
      result **= second_number

      end
    end

    print 'Result: '
    puts result
  end

Ответы (0 шт):