Hi --

On Sun, 15 Jan 2006, Jeff Cohen wrote:

> For extra credit, anybody know how I can make sure I can ignore comments
> and quoted strings?  I want to make sure I ignore these things:
>
> if option_exists # handle class options
>
> as well as
>
> puts "Your are in a class by yourself"
>
> But those are advanced... if I can just get the first one working I'll
> be grateful!

You might try this:

   /^\s*class\s+(\w+)/

which will only match "class ..." at the beginning of a line or with
only spaces to its left.  It's certainly not impossible to get false
positives or negatives this way, but in the normal course of a
normally-written Ruby program file it should be close to 100%.

Don't forget, though, that you might get "::" in a class name, like
this:

   module M
   end

   class M::C
   end

and just going for \w+ will give you the module name, not the class
name.


David

-- 
David A. Black
dblack / wobblini.net

"Ruby for Rails", from Manning Publications, coming April 2006!
http://www.manning.com/books/black