From: Robert Klemme Date: 2004-12-02T22:42:44+09:00 Subject: Re: singleton methods : when are they not permitted? "Brian Schr�der" schrieb im Newsbeitrag news:20041202141630.4a975ff1@black.wg... > On Thu, 2 Dec 2004 21:27:43 +0900 > "Robert Klemme" wrote: > > > [snip] > > But > > > > >> 2.times do |i| puts /abc#{i}/o.id end > > 135012888 > > 135012888 > > => 2 > > > > Note the usage of flag "o". > > > > Kind regards > > > > robert > > > > Interesting, but what is the use case for this? It seems to be quite dangerous > because it makes code really difficult to understand. It's an optimization flag. It's for those cases where you need interpolation in a regexp but you know it will never change again. This is usual in little scripts, like fake-grep.rb rx = ARGV.shift while ( line = gets ) puts line if /#{rx}/o =~ line end I think Ruby inherited this flag from P**l. Note: of course you can achieve the same with this little change: rx = /#{ARGV.shift}/ while ( line = gets ) puts line if rx =~ line end > E.g. The causual reader would expect this to yield nil, 0, nil. > > > 3.times do | i | puts /#{i}/o =~ '1' end > nil > nil > nil > => 3 > > I shall read my pickaxe again ;) :-) Regards robert