Ahh, I think I understand what you're doing.
Something like this maybe?
class RegExProcessor
attr_reader :results
def initialize(pattern, location)
@pattern, @location = pattern, location
@result =
end
def process_line(line)
if m = @pattern.match(line)
@results << m[@location]
end
end
end
class ProcProcessor
attr_reader :results
def initialize(&block)
@block = block
@results =
end
def process_line(line)
if x = @block.call(line)
@result << x
end
end
end
processors = [
bracketThing = RegExProcessor.new(/#include\s*[<"](.*)[>"]/, 1),
specialThing = ProcProcessor.new { |line| line[2..4] + line[8..12] },
]
File.open("foo.cpp") do |f|
f.each_line do |line|
processors.each {|p| p.process_line(line) }
end
end
includesArr = bracketThing.results
specialArr = specialThing.results
···
-----Original Message-----
From: Ben [mailto:benbelly@gmail.com]
Sent: Monday, 26 September 2005 11:57 AM
To: ruby-talk ML
Subject: Re: Overloading
On 9/25/05, Daniel Sheppard <daniels@pronto.com.au> wrote:
I don't quite understand your original problem (wouldn't the the
ProcExtractor and the PatternLocationExtractor be two different
things?),
Well, maybe. I would like to pass through the files just once - there
are likely to be several hundred files, and they will sometimes be quite
long. I was hoping to use Ruby's ability to store multiple types to do
that. Hmm. Maybe . . .
I'll make a pattern / location parser, and the extracter will just hold
parsers. That makes more sense. Thanks.
It always helps to talk things out, eh?
-Ben
#####################################################################################
This email has been scanned by MailMarshal, an email content filter.
#####################################################################################