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

Tyler Walker
Tyler Walker
609 Points

I didn't feel prepared to answer this question. I am also not entirely sure what they are asking. Skipped it

This is the second excercise in this course that has felt out of order.

I have been super comfortable with every exercise in TeamTree house until this one, and one earlier. (will go back and comment)

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

1 Answer

Mohamed Fouda
Mohamed Fouda
Courses Plus Student 6,202 Points

To understand this example First parse_answer method take one argument which is answer and we declare the aswer input kind to our method to. be string by defult so any input to our parse_answer will be recognized as string kind

But if our parse_method declared input with kind number only it must use answer.to_i to transform it from kind string to kind number

That’s very useful as it gives you flexibility to deal with strings which can include characters and or numbers but if you got input only in numbers you can transform it from string to into integers