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

help! i do not understand the question fully

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

return answer

end

code i have tried

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

  return answer


end
Tom Sager
Tom Sager
18,987 Points

The value of answer is already assigned when the parse_answer is called. There is no reason to 'gets' it.

2 Answers

Tom Sager
Tom Sager
18,987 Points

The value of answer is already assigned when the parse_answer is called. There is no reason to 'gets' it.

"answer = gets" will get you input along with a default type of string. for example, when you assign "parse_answer("whatever") " it actually means ("whatever", "string") but, if you want to type a number parse_answer("1") the default type of the "1" is a string not a integer. however, if you give a description like("1","number")

it will convert "1" to a integer 1