dictionary = File.foreach('dictionary.txt').map { |line| line.split('\n') }
dictionary.each{|word|
puts word.length
if word.length == 5
puts word
end
}
It says the value for each |word| is only 1. Anyone have a clue why? Thanks.
map { ... split('\n') }should return array of arrays, each of subarrays with only one element (as the delimiter\nis at the end). You wantline.strip, notline.split. Voting to close as typo.