From: "Simon Kröger" Date: 2005-12-10T06:37:28+09:00 Subject: Re: new to Ruby - pls help in translating this dblack@wobblini.net wrote: >> quantities = Hash.new{|h, k| h[k]=0} >> ARGF.each{|l| quantities[l.chomp.to_i] += 1} > > > Since you're doing a h[x] += 1 thing, you don't need to do the > auto-assignment in the block: > > quantities = Hash.new(0) > > will work fine. yes, saw that after pressing the submit button, but as said before using this form of Hash.new is source of hard to track bugs. > Also, String#to_i is smart enough not to need the chomp. > > So, as so often happens, code evaporates from the screen as one works > on a Ruby program :-) you are so true: require 'set' seen = Set.new puts ARGF.reject{|l| seen.add? l} cheers Simon