Ruby ‘duck typing’ addiction

I just had another reminder why I like late binding and flexible typing so much: I had written a handy little utility in Ruby for collecting some data, writing to an open file as data was collected and processed. Initially, I thought: why buffer everything in memory? Then I had the need to use the same functionality to dynamically generate a download from a web app, but I did not have to change any code: I need to collect text and send it out in a Rails controller (instead of using a view) back to a client web browser – I needed in-memory data, not a local file.

Well, since both String and File classes support
Anyway, not a big deal, but it did save me refactoring some old code for a new use, saving a few minutes.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>