On Feb 24, 8:57    
> I don't see the big advantage of Array#to_csv over a more traditional
> CSV::from_a(arr), other than a few more characters to type.    
> encapsulated.

The big advantage is that, when writing a method that needs to receive
CSV data as an argument, you don't have to do type checking on the
argument - any object that responds correctly to the #to_csv message
can be used.

    def i_need_csv( obj )
      data = obj.to_csv
      do_something_with( data )
    end

This gives more freedom to the user of the library who might have an
object of their own class which knows how to turn itself into CSV
data. Your suggestion would lead to something like:

    def i_need_csv( obj )
      data = case obj
      when Array
        CSV::from_a( obj )
      when Hash
        CSV::from_hash( obj )
      else
        raise "Sorry, I'm not duck-type friendly!"
      end
    end

Yuck.

> The disadvantage of making Array#to_csv is that you are
> modifying a global "variable" (the Array class).

I'll take that disadvantage (in combination with good test coverage!)
over having to write verbose, type-checking code any day.

--
Regards,

John Wilger