[英]gets.chomp to match ENTER (in ruby)
我以為(一段時間...做循環)
gets.chomp != ''
可能與從終端返回的回車符相匹配。 沒有。 我不明白什么? 謝謝。
String#chomp從被調用的字符串中刪除回車符。
如果刪除了chomp
它將為您提供預期的輸出。 見下文:
2.1.2 :001 > def foo
2.1.2 :002?> while true do
2.1.2 :003 > puts gets != ''
2.1.2 :004?> end
2.1.2 :005?> end
=> :foo
2.1.2 :006 > foo
a
true
b
true
c
true
1
true
2
true
# about to press enter
true
true
希望這可以幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.