From: Rick DeNatale Date: 2010-04-03T10:58:02+09:00 Subject: Re: return number of spaces at the beginning of a line On Fri, Apr 2, 2010 at 8:29 PM, Josh Cheek wrote: > On Wed, Mar 31, 2010 at 12:11 PM, Aldric Giacomoni wrote: > >> Josh Cheek wrote: >> > On Tue, Mar 30, 2010 at 9:35 AM, Robert Klemme >> > wrote: >> > >> >> 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, >> >> No, they are created as soon as the regular expression is parsed. I >> believe Wycats explained that somewhere else, but I can't find the link >> at the moment. >> -- >> Posted via http://www.ruby-forum.com/. >> >> > I was reading Rick DeNatale's blog Talk Like A Duck which directed me to a > different post of Yehuda Katz's, where I found a more explicit explanation: > "When you use =~, there is no actual MatchData object, $1 just behaves like > it was indexing into an implicit MatchData" > http://yehudakatz.com/2010/02/21/ruby-is-not-a-callable-oriented-language/ > > He doesn't say anything about $&, but I'd be surprised if it wasn't the > same. > Though a quick survey of the pickaxe and The Ruby Programming Language > didn't imply this implementation detail. The 'global' variables which are set by regular expression matches aren't really global, they are 'frame local' http://talklikeaduck.denhaven2.com/2008/11/17/in-ruby-globals-arent-always-global -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale