Ruby Ruby Loops Build a Simple Contact List Methods That Return a Value

Andrew Carr
Andrew Carr
10,979 Points

Why if function does not work.

I tried using the following code but it doesn't seem to complete the code challenge. I understand "answer = answer.to_i if kind == "number"' is simpler, but how is my code inherently different?

Thanks!

ask.rb
def parse_answer(answer, kind="string")
  if answer.kind == "number"
    answer = answer.to_i
  end
  return answer
end
if kind == "number"

1 Answer

Jeff Jacobson-Swartfager
Jeff Jacobson-Swartfager
15,412 Points

You are comparing the value in the kind method on answer to the string "number". The answer object that is being passed into parse_answer may not have a kind method.

The construction of the parse_answer method is looking to get at least 1 required argument (answer) and 1 optional argument (kind).

You need to test the value of the optional kind argument to pass.