2010/6/29 Tony Arcieri <tony.arcieri / medioh.com>: > On Tue, Jun 29, 2010 at 11:50 AM, Doug Jolley <ddjolley / gmail.com> wrote: > >> Unfortunately that is precisely my case and that is precisely what I was >> trying to avoid. =A0(And, unfortunately, I don't have any control over t= he >> target code.) > > It's Ruby. =A0You can always patch or alias_method_chain the target code = if > you're willing to bear some slight brittleness. Is this always possible? Wouldn't you need some knowledge of the inner workings of the target code? In this case for example, does it open the file with File.open or maybe with File.foreach? This is an interesting point of interface design: usually it is more convenient to just pass a file name somewhere and that method opens the file (or URL) and reads the data. But from a modularity point of view it is generally better to pass an open IO like instance. You can nicely layer this e.g. class X # convenience method that will open the file for you def read_file(path) File.open path |io| read io end end # yet another convenience method def read_url(url) ... end # read the data def read(io) io.each_line do |line| # whatever end end end The only drawback here is the additional method needed but convenience comes at a price. :-) Kind regards robert --=20 remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/