Matthew Harris wrote:
> I don't know if this was posted previously, but I had the idea of a
> Array#to_proc, an example would be:
>
> [9, 19, 29].map(&[:succ, :to_s, :reverse])
> => ["01", "02", "03"]
>
> I've seen people ask questions such as arr.map(&'meth1.meth2.meth3')
> but I think using the Array#to_proc solution is cleaner.
>
> Would this actually prove useful? It would seem that using the normal
> block form would be just as much typing, though.

Well, unless Array's got something else to do with #to_proc, it doesn't
seem to me a dab things per say. What might be more intersting though
is what I suggsed in the Symbol.to_proc is beautiful thead combined
with a way to force +self+ to be passed rather then the result. It
would be something like:

  [9, 19, 29].map.succ!.to_s!.reverse
  => ["01", "02", "03"]

Where the ! is forcing self to be returned rather then the regular
result. I'm not even sure this would conflict with the defintion of
#succ! either. Altghough it could conflict with other defintions of
bang methods that don't return self (rare but out there). Is ther an
alternate notation?


Oh. While were at it:

  class Hash
    def to_proc
      Proc.new { |o|
        each {|k,v| o.__send__("#{k}=", v)
      }
   end
 end

Usage:

  class X
    attr_accessor :a, :b
    def initialize( &blk )
      blk[self]
    end
  end

  h = {:a=>1, :b=>2}
  X.new( &h )

Of course, it's still no as good as uniform parameters, eg no special
form for blocks. :(

T.