From: Robert Klemme Date: 2010-03-31T00:35:54+09:00 Subject: Re: return number of spaces at the beginning of a line 2010/3/30 Colin Bartlett : > On Tue, Mar 30, 2010 at 2:18 PM, Robert Klemme > wrote: >> 2010/3/30 Jesse B. : >>> This second post with the "spaces only" fix seems to meet all the needs >>> of what I was looking for. >>> >>> I love that this got 9 replies in the middle of the night. >>> thanks everyone for your help. >> >> What do you mean, middle of the night?  It's quite sunny here and the >> sun isn't even going to settle soon. ;-) > > Well, it's also nowhere near the middle of the night here > (n*100 kilometres west of Robert?, where 0 < n < 13?) Yeah, that sounds about right. > but it's definitely not "quite sunny"! In fact, it's raining! > (To quote from "A Song of the Weather" >  by Flanders and Swann - 1950s/1960s sort of English Tom Lehrer's: >  April brings the sweet spring showers. >  On and on for hours and hours.) I think I have to hurry: rain radar indicates showers coming my way. > How about this? I think it's different from the other solutions(?), > it seems to work, and it doesn't create a string object(?). >  (str =~ /[^ ]/) || str.length 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. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/