Parsing mathmatical functions
Here's a toy program to illustrate the separation of user input collection from the string matching that determines which calc to use, as we discussed in the comments.  Note that the class NamedCalculations has no knowledge of IO with the user.  All the IO is encapsulated in CmdLineCalculator.

When I find a match, I just evaluate it with the argument pi.  In your real application, you'd need to do further process to gather the user's input for the argument.

Also note how if we decide we want to change which calculations we support (one of the most likely changes for the application), it becomes a 1 line change, and the user input processing code doesn't need to be touched.

class NamedCalculations

  # a hash of named calcs
  # eg, {cos: Math.method(:cos), sin: Math.method(:sin) }
  def initialize(calc_definitions)
    @calc_definitions = calc_definitions
    @calc_names = @calc_definitions.keys.map(&amp;:to_s)
  end

  def method_for(calc_name)
    calc_name = calc_name.to_sym
    raise "Invalid Calculation Name" unless @calc_definitions.key? calc_name
    @calc_definitions[calc_name]
  end

  def exact_match?(input)
    @calc_names.any? {|name| input == name}
  end

  def partial_match?(input)
    @calc_names.any? {|name| name.include? input}
  end

end


class CmdLineCalculator

  def initialize(named_calcs)
    @named_calcs = named_calcs
    @input = ''
  end

  def start
    begin
      system("stty raw -echo")
      collect_user_input while not calc_complete?
      show_answer
    ensure
      system("stty -raw echo")
    end
  end

  private

  def collect_user_input
    @input += next_input_char
    validate_input
    echo_last_char
  end

  def validate_input
    raise "Invalid Calculation" unless @named_calcs.partial_match? @input
  end

  def next_input_char
    STDIN.getc
  end

  def echo_last_char
    STDOUT.putc @input[-1]
  end

  def calc_complete?
    @named_calcs.exact_match? @input
  end

  def show_answer
    selected_method = @named_calcs.method_for(@input)
    value_at_pi = selected_method.call(Math::PI)
    STDOUT.puts "\nThe #{@input}(pi) = #{value_at_pi}" 
  end

end

my_calcs = {cos: Math.method(:cos), sin: Math.method(:sin) }
client = CmdLineCalculator.new(NamedCalculations.new(my_calcs))
client.start