J
Jeff Cohen
I'm trying to parse ruby files to find all the class definitions in the
file. For each line in the file, I thought I could use the following to
pull out the class name:
\bclass\b(\w+)\b
so then $1 would give me the class name.
But it doesn't work:
irb(main):001:0> line = "class Article < MyBaseClass"
=> "class Article < ActiveRecord::Base"
irb(main):002:0> line =~ /\bclass\b(\w+)\b/
=> nil
I think I narrowed down the problem to my use of \w, but I can't
understand why.
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!
Thanks,
Jeff
file. For each line in the file, I thought I could use the following to
pull out the class name:
\bclass\b(\w+)\b
so then $1 would give me the class name.
But it doesn't work:
irb(main):001:0> line = "class Article < MyBaseClass"
=> "class Article < ActiveRecord::Base"
irb(main):002:0> line =~ /\bclass\b(\w+)\b/
=> nil
I think I narrowed down the problem to my use of \w, but I can't
understand why.
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!
Thanks,
Jeff