Reputation: 11
def pregunta
reply = gets.chomp.downcase
if reply == 'si'
puts 'Correcto'
end
if reply == 'no'
puts 'Incorrecto'
end
end
pregunta 'alfkjdasñlfj?'
After I ask a question ("pregunta" is question in english), the program should tell me if I'm right ("correcto") or wrong ("incorrecto") when I enter an answer ("si" or "no"). Instead of getting an answer, I get an "ArgumentError". What am I doing wrong?
I'm using Ruby 1.9.3-p194
Upvotes: 1
Views: 74
Reputation: 15673
pregunta doesn't take a parameter, but you pass one anyways. I might be wrong, but wasn't what you were trying to do something like this:
def pregunta(preg)
puts preg
reply = gets.chomp.downcase
if reply == 'si'
puts 'Correcto'
end
if reply == 'no'
puts 'Incorrecto'
end
end
Upvotes: 2
Reputation: 20320
You are calling pregunta 'alfkjdasñlfj?' but that method has no arguments.
def pregunta(answer)
reply = answer.chomp.downcase
if reply == 'si'
puts 'Correcto'
end
if reply == 'no'
puts 'Incorrecto'
end
end
pregunta gets
maybe ?
Upvotes: 1
Reputation: 553
You don't have any parameters in your method declaration.
You'll need something like this:
def pregunta(foo)
if foo == 'bar'
true
end
end
Upvotes: 1
Reputation: 106389
You're not passing in a value to the function call, you're reading it from the terminal. Call the function and then enter in your string.
pregunta
si
Correcto
=> nil
Upvotes: 1