From: transfire@... Date: 2006-07-15T21:25:29+09:00 Subject: Re: Preferred monkeypatching technique Daniel Martin wrote: > Eric Hodel writes: > > > You don't need a mutex. > > > > class Symbol > > @gensym_count = 0 > > def self.gensym > > ("__gensym__%X" % @gensym_count += 1).intern > > end > > end > > Okay, but now if two different files include this exact code, you're > re-generating the same symbols. This is why I used ||=, making your > code: > > class Symbol > @gensym_count ||= 0 > def Symbol.gensym > ("__gensym__%X" % @gensym_count += 1).intern > end > end What if the symbol is already used? define_method( :__gensym__0 ) do ... end Symbol.gensym => :__gensym__0 I know, unlikley, but gensym's return is not neccessarily unique. T.