On Wed, Nov 14, 2012 at 05:38:12AM +0900, headius (Charles Nutter) wrote:

[snip]

> And then there's this:
> 
> class Foo < SomeParent
>   def baz(str)
>     ary.map {|name| str.camelize + name}
>   end
> end
> 
> In this case, you have to check even more places for refinements to know what methods will be called:
> 
> * Foo may have been previously refined. You must look for all reopenings of Foo to know what will be called.
> * SomeParent or its parents may have been previously refined. You must look for all reopenings of SomeParent and its parents.
> * The map method may force refinements on the block. you must look for all implementations of map() that might be called here to see if they force refinements into the block.
> 
> This is supposed to be simpler?

I have to agree.  It seems like this would be *much* more difficult to
debug than if `camelize` is just monkey patched on to String.

This code:

  class Foo < SomeParent
    def baz(str)
      cached = str.camelize
      ary.map {|name| cached + name}
    end
  end

Could have a completely different meaning than this code:

  class Foo < SomeParent
    def baz(str)
      ary.map {|name| str.camelize + name}
    end
  end

That seems extremely bad.

-- 
Aaron Patterson
http://tenderlovemaking.com/