入門停留在第8章:克里斯·派恩學習編程紅寶石8章:按字母順序排列你的陣列
種類儘可能多的話,因爲我們希望每行 一個字,一直持續到我們只需按Enter鍵上一個空行 重複按字母順序給我們回話。 使用「排序」
所以,這裏是我得到了什麼,但我在使用沒有得到的第一個字推入陣[除其他外]
# alphabetting
puts 'Tell us some of your favorite things!'
# create an array
words = []
while gets.chomp != ''
words.push gets.chomp
words.sort
puts words
end
這篇而有趣的問題它現在可行......我是否必須在那裏擁有「東西」?似乎調皮在'while'循環內分配。
puts 'Tell us some of your favorite things!'
words = []
puts words
while (thing = gets.chomp) != ''
words.push thing
end
puts words.sort
你嘗試做 「放話」 之前?這或嘗試將變量存儲在gets.chomp中,然後執行words.push? – 2011-12-21 04:12:59