From: "Brian Schröder" Date: 2004-12-02T20:34:02+09:00 Subject: Re: singleton methods : when are they not permitted? On Thu, 2 Dec 2004 19:12:43 +0900 "Robert Klemme" wrote: > I prefer to view a literal as a special kind of expression that yields an > instance on each execution. Whether this is always the same instance (as > for symbols, Fixnum and surprisingly also for Bignum and Regexp) or > whether it's a different instance (as for strings, arrays and hashes) > depends on the literal. That regexps are always the same surprised me also, but it is nice. So it is not optimization to extract a regexp into a constant instead of writing it in the loop. (Btw: Always when I'm trying to optimze something in ruby, it gets slower. Ruby follows exactly my mindset when programming, and when I try to change my mind on how the computer actually works it out, I'm running in the wrong direction.;) irb(main):005:0> 2.times do |i| puts /abc/.id end 538420744 538420744 => 2 But it can't always be true irb(main):006:0> 2.times do |i| puts /abc#{i}/.id end 538396754 538396704 => 2 Or maybe one should clarify it such, that a regexp with interpolation is no longer a literal. Regards, Brian -- Brian Schr�der http://www.brian-schroeder.de/