-2
我有一個哈希:Hash和每個方法
lines = {
:n => ["Times Square", "34th", "28th", "23rd", "Union Square", "8th"],
當我這樣做:
first_line = lines[:n]
a = first_line[0]
b = first_line[4]
(a..b).select{|x| puts x}
我得到一個超過極限。有沒有辦法打印範圍從a
到b
?
大家好,你可以停止標誌着我失望哎呀:) ......我忘了了最新我的答案... BTW另一種爲上述方案是
lines = {
:n => ["Times Square", "34th", "28th", "23rd", "Union Square", "8th"}
puts first_line = lines[:n]
puts first_line.slice(0, 5) => "Times Square", "34th", "28th", "23rd", "Union Square"
無法複製。我的代碼沒有無限循環。事實上,你的代碼完全符合你的要求;它只在「a」和「b」內打印範圍。 – sawa
啊... GA的「MTA」作業... ;-) – Pavling