gpt4 book ai didi

ruby - 输入值的条件总是返回 false (RUBY)

转载 作者:数据小太阳 更新时间:2023-10-29 08:59:38 25 4
gpt4 key购买 nike

我想知道为什么即使我输入“y”,条件总是 false

puts "Would you like to continue [y/n]"
confirm = gets
puts confirm == "y" # why this is not true even I type "y"

if confirm == "y"
puts "Input is y"
end

最佳答案

尝试使用confirm = gets.chomp 因为gets set you enter with \n in the end

> a = gets
> y
=> "y\n"

关于ruby - 输入值的条件总是返回 false (RUBY),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39653788/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com