Ruby chomp有什么用?
在此代码段中:Ruby chomp有什么用?,ruby,Ruby,在此代码段中: puts "You enter a dark room with two doors. Do you go through door #1 or door #2?" print "> " door = $stdin.gets.chomp 对get for的返回值的chomp调用是什么?就像在其他情况下使用chomp一样。若您从gets获取字符串,它将带有尾随的新行字符。chomp将其移除 在上面的示例中 从stdin获取用户输入,并返回一个字符串,该字符串将传递给ch
puts "You enter a dark room with two doors. Do you go through door #1 or door #2?"
print "> "
door = $stdin.gets.chomp
对get for的返回值的chomp调用是什么?就像在其他情况下使用chomp一样。若您从gets获取字符串,它将带有尾随的新行字符。chomp将其移除 在上面的示例中
从stdin获取用户输入,并返回一个字符串,该字符串将传递给chomp
chomp返回一个新字符串,如果存在,则从str的末尾删除给定的记录分隔符。使用google解决此类问题。ruby chomp将直接引导您访问Documentation此字符串不会传递给chomp,但会在此字符串上调用chomp。