From: Bill Kelly Date: 2009-03-30T18:55:03+09:00 Subject: Re: Symbols garbage collector in Ruby1.9, fixed? From: "I単aki Baz Castillo" > 2009/3/30 Bill Kelly : > > > > From: "I単aki Baz Castillo" > >> > >> A way to check if a Symbol already exist would be enought for me, but > >> it doesn't work: > >> To know all the current Symbols I can inspect Symbol.all_symbols, but > >> if I want to check a Symbol: > >> Symbol.all_symbols.include?(:new_symbol) > >> this will always return true since :new_symbol is automatically added > >> XDDD > > > > potential_new_symbol = "xyzzy" > > Symbol.all_symbols.map {|s| s.to_s}.include? potential_new_symbol > > Thanks but it is too slow: > > Benchmark.realtime{ Symbol.all_symbols.map {|s| s.to_s}.include? "qwe" } > => 0.00371980667114258 > > I cannot do this test for each header in each received message. I assumed you had a plan for that. :) We could cache them as a hash, for rapid lookup: @known_symbols = Hash[ *Symbol.all_symbols.map {|s| [s.to_s,true]}.flatten ] # Later.... @known_symbols.include? "xyzzy" Regards, Bill