所以我跟着做了心理测试墨西哥卷饼,玉米饼,wets_bed程序在克里斯·派恩...是的,我改成了"Escape: the Pina Colada song“的歌词,但除此之外,保持不变。
然而,它在第一个“请求”时就卡住了。。。帮助?
我不想大刀阔斧地改变这一点,只是想找出程序挂起的地方。
# Nice little questionnaire
def ask question
good_answer = false
while (not good_answer)
puts question
reply = gets.chomp.downcase
if (reply == 'yes' or reply == 'no' )
good_answer == true
if reply == 'yes'
answer = true
else
answer = false
end
else
puts 'Please answer "yes" or "no".'
end
end
answer # This is what we return (true or false)
end
puts 'Hello, and thank you for smoking.'
puts
ask 'Do you like pina-coladas?'
ask 'Do you like getting caught in the rain?'
risky_business = ask 'Do you know what your sig other likes?'
ask 'Are you into yoga?'
ask 'Do you have half a brain?'
puts 'Just a few more questions.'
ask 'Do like the feel of the ocean?'
ask 'Are you into champagne?'
puts
puts 'DEBRIEFING'
puts 'Thank\'s for all the fish'
puts
puts risky_business就这样。我想知道这是否可能是Ruby版本的问题?
谢谢!
发布于 2012-01-06 03:46:56
这行有问题吗?good_answer == true
难道不应该是good_answer = true吗?
发布于 2012-01-06 05:38:08
如果你打开了警告,Ruby本身就会告诉你good_answer == true行没有意义。
您可以在代码中使用$VERBOSE = true打开警告,或者让unix变量RUBYOPT包含-w。
发布于 2012-01-06 04:25:11
顺便说一句,我会像这样重写ask函数,使其更符合Ruby的方式:
def ask(question)
puts question
while reply = gets.chomp.downcase
if %w( yes no ).include?(reply)
answer = if reply == 'yes' then true else false end
break
else
puts 'Please answer "yes" or "no".'
end
end
answer
endhttps://stackoverflow.com/questions/8748672
复制相似问题