爲什麼我的foo()
函數打印字符串「YAAR」的長度爲5?對Ruby長度屬性感到困惑
def foo()
map = Hash.new
File.open('dictionary.txt').each_line{ |s|
word = s.split(',')
if word.any? { |b| b.include?('AA') }
puts word.last
puts word.last.length
end
}
end
someFile.txt
265651,YAAR
265654,YAARS
輸出
YAAR
5
YAARS
6
的長度沒有說謊。試試'puts「>」+ word.last.inspect +「<」'看看會出現什麼。 – 2013-02-28 01:06:50