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

Tyler Proctor
Tyler Proctor
11,458 Points

I've compared this with code from the video and they appear to be doing the exact same thing. What am I missing?

I'm setting the answer to a string that the user enters, then converting it to an integer if it is a number, and then returning. I don't understand how this is incorrect. Does it want me to actually call the method as well?

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

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 144,813 Points

Hey Tyler,

You're pretty much correct, except you added something the challenge didn't ask for. The value for answer is being grabbed when the function is called, so I'm not sure why you added answer = gets.chomp. If you delete that line, the code will pass the challenge.

Keep Coding! :) :dizzy:

Tyler Proctor
Tyler Proctor
11,458 Points

Thank you! I just want to make sure I understand- so you don't need the gets method to assign a value to answer because you're already assigning the value of answer when you pass a string into the parse_answer method?