From: Robert Klemme Date: 2010-03-25T19:19:31+09:00 Subject: Re: hash problem 2010/3/25 Adam Nelreth : > F. Senault wrote: >> Le 25 mars � 10:29, Adam Nelreth a �crit : >> >>> but this doesn't work :/ >> >> It should.  Show us your whole code, not just snippets - the problem >> lies somewhere else. >> >>>> h = Hash.new(0) >> => {} >>>> if h.has_key?("1.2.3.4") >>>>   puts "In table." >>>>   else >> ?>     h["1.2.3.4"] = 1 >>>>   end >> => 1 >>>> if h.has_key?("1.2.3.4") >>>>   puts "In table." >>>>   else >> ?>     h["1.2.3.4"] = 1 >>>>   end >> In table. >> => nil >>>> h.has_key?("1.2.3.4") >> => true >> >> Fred > > Ok - here is code: > > login = 'aaa' > test = Hash.new > > imap = Net::IMAP.new('imap-server',993,true) > puts "passwd: " > pass = gets.chop > imap.login(login,pass) > imap.select('example') > imap.uid_search(["SUBJECT", "To-check", >                 "NOT", "SEEN"]).each do |uid| >        mess = imap.uid_fetch(uid, "ENVELOPE")[0].attr["ENVELOPE"] >        title = mess.subject >        ip = > /(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/.match(title) >        if test.has_key?(ip) >                test[ip] += 1 >        else >                test[ip] = 1 >        end > end > imap.logout() > imap.disconnect() > > I try with else test[ip] = 1 and without else - it still doesn't work > like I need - maybe there is problem with "" or '' because I don't set > it when I put key to hash table ip is of type MatchData. What you want is a String. irb(main):001:0> ip = "foo".match /o+/ => # irb(main):002:0> ip[0] => "oo" Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/