Read lines one at a time and initialize a hash : IO.foreach « File Directory « Ruby






Read lines one at a time and initialize a hash

words = {}
IO.foreach("/usr/share/dict/words") {|w| words[w] = true}

 

Related examples in the same category

1.Print all lines containing the word "target"