sdsykes/fastimage — pull request #29 by guilhermesimoes (2014-04-26 23:16:43+00:00)
Title: Replace recursion with iteration and other refactorings

At RailCconf, DHH incentivized programmers to read through a complete gem. I had been using this gem for so long and yet I had never looked into its code that I decided to do it today.

One method that I couldn't wrap my head around was `fetch_using_http_from_parsed_uri`, mainly because of its use of recursion. I decided to replace that with iteration and through this exercise, I ended up making a few other changes.

There are a few things I don't like about this refactoring:

* I introduced a new instance variable (`@http_class`) but on the upside I removed another (`@redirect_count`)

* The variable `@http_class` is set in the `fetch_using_http` method which seems out of place.

* The error `ImageFetchFailure` is raised in two different places in the `fetch_using_http_from_parsed_uri` method.

However, overall, the code seems a little simpler (to me, at least).

I'm not sure if these changes are welcome or even warranted. I mean, "if it ain't broke, don't fix it". But I had a lot of fun doing this, and I don't see any harm in just showing what I accomplished through this refactoring exercise.