# Overloading

**URL:** <https://rubytalk.org/t/overloading/21093>\
**Category:** ruby-talk\
**Created:** [26 September 2005 03:52 UTC](https://rubytalk.org/t/overloading/21093 "2005-09-26T03:52:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_Sheppard](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@Daniel\_Sheppard](https://rubytalk.org/u/Daniel_Sheppard)\
**Post date:** [26 September 2005 03:52 UTC](https://rubytalk.org/t/overloading/21093/1 "2005-09-26T03:52:35Z")

</div>

Ahh, I think I understand what you're doing.

Something like this maybe?

class RegExProcessor  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;attr\_reader :results  
&nbsp;&nbsp;def initialize(pattern, location)  
&nbsp;&nbsp;&nbsp;&nbsp;@pattern, @location = pattern, location  
&nbsp;&nbsp;&nbsp;&nbsp;@result =   
&nbsp;&nbsp;end  
&nbsp;&nbsp;def process\_line(line)  
&nbsp;&nbsp;&nbsp;&nbsp;if m = @pattern.match(line)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@results \<\< m[@location]  
&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;end  
end

class ProcProcessor  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;attr\_reader :results  
&nbsp;&nbsp;def initialize(&block)  
&nbsp;&nbsp;&nbsp;&nbsp;@block = block  
&nbsp;&nbsp;&nbsp;&nbsp;@results =   
&nbsp;&nbsp;end  
&nbsp;&nbsp;def process\_line(line)  
&nbsp;&nbsp;&nbsp;&nbsp;if x = @block.call(line)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@result \<\< x  
&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;end  
end

processors = [  
&nbsp;&nbsp;bracketThing = RegExProcessor.new(/#include\s\*[\<"](.\*)[\>"]/, 1),  
&nbsp;&nbsp;specialThing = ProcProcessor.new { |line| line[2..4] + line[8..12] },  
]

File.open("foo.cpp") do |f|  
&nbsp;&nbsp;f.each\_line do |line|  
&nbsp;&nbsp;&nbsp;&nbsp;processors.each {|p| p.process\_line(line) }  
&nbsp;&nbsp;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.  
> #####################################################################################
