From: "David A. Black" Date: 2009-01-31T20:52:39+09:00 Subject: Re: global generator of unique symbols Hi -- On Sat, 31 Jan 2009, Thomas Hafner wrote: > Hello, > > is there a global generator of unique symbols? See article > why that can be needed. There I > have defined myself a generator, but that's no real solution: if > software is going to be put together from different libraries, only > one common generator should be used by all software parts to prevent > symbol clash. > > With ``generator of unique symbols'' I mean: the first time since > program start it will generate any symbol. Any other time it will > generate a symbol that differs from all already generated symbols. Based on a 2005 post from Jeremy Kemper, based in turn on a response from Ryan Leavengood: $unique_symbol = 'AAAAAAAA' def generate_symbol $unique_symbol.succ!.to_sym end As James Gray pointed out in the same thread, be careful with runaway symbol generation, since symbols aren't garbage collected. David -- David A. Black / Ruby Power and Light, LLC Ruby/Rails consulting & training: http://www.rubypal.com Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2) http://www.wishsight.com => Independent, social wishlist management!