From: Josh Cheek Date: 2010-04-01T02:16:25+09:00 Subject: Re: return number of spaces at the beginning of a line --000e0cd11326b4ddcb04831be4a1 Content-Type: text/plain; charset=ISO-8859-1 On Tue, Mar 30, 2010 at 9:35 AM, Robert Klemme wrote: > I'm afraid, that is not correct; the String is created as a side > effect and stored in a global variable: > > irb(main):001:0> str = " foo" > => " foo" > irb(main):002:0> str =~ /[^ ]/ > => 3 > irb(main):003:0> $& > => "f" > > And it has the disadvantage over str[/\A */].length that likely is > slower because of the alternative. > > > There was a blog by Yehuda Katz that implied to me that these globals weren't set until you asked for them, but upon re-reading, it isn't really clear to me what actually happens http://yehudakatz.com/2010/02/25/rubys-implementation-does-not-define-its-semantics/ --000e0cd11326b4ddcb04831be4a1--