The fun continues

class Class
     def to_proc
       proc{new}
     end
   end

   (1..5).map(&Array) => [[], [], [], [], []]
   (1..5).map(&String) => ["", "", "", "", ""]

Mmmmmmmmm, Ruuuuuuubyyyyyyy... *drool*

Daniel Schierbeck wrote:

  class Class
    def to_proc
      proc{new}
    end
  end

  (1..5).map(&Array) => [, , , , ]
  (1..5).map(&String) => ["", "", "", "", ""]

Even cooler:

   class Class
     def to_proc
       proc{|*args| new(*args)}
     end
   end

   class Person
     def initialize(name)
       @name = name
     end

     def inspect
       @name.to_str
     end
   end

   %w(john bob jane hans).map(&Person) => [john, bob, jane, hans]

Daniel

Daniel Schierbeck wrote:

Daniel Schierbeck wrote:

  class Class
    def to_proc
      proc{new}
    end
  end

  (1..5).map(&Array) => [, , , , ]
  (1..5).map(&String) => ["", "", "", "", ""]

Even cooler:

  class Class
    def to_proc
      proc{|*args| new(*args)}
    end
  end

  class Person
    def initialize(name)
      @name = name
    end

    def inspect
      @name.to_str
    end
  end

  %w(john bob jane hans).map(&Person) => [john, bob, jane, hans]

Daniel

This could have been done just as well by modifying Enumerable#map in the core, without adding new syntax.

Regards,

Dan

New syntax?

···

On Jun 4, 2006, at 2:27 PM, Daniel Berger wrote:

Daniel Schierbeck wrote:

Daniel Schierbeck wrote:

  class Class
    def to_proc
      proc{new}
    end
  end

  (1..5).map(&Array) => [, , , , ]
  (1..5).map(&String) => ["", "", "", "", ""]

Even cooler:
  class Class
    def to_proc
      proc{|*args| new(*args)}
    end
  end
  class Person
    def initialize(name)
      @name = name
    end
    def inspect
      @name.to_str
    end
  end
  %w(john bob jane hans).map(&Person) => [john, bob, jane, hans]
Daniel

This could have been done just as well by modifying Enumerable#map in the core, without adding new syntax.

Regards,

Dan

Daniel Berger wrote:

This could have been done just as well by modifying Enumerable#map in the core, without adding new syntax.

Where's the fun in that? :slight_smile:

I simply had to share my love with the wonderful #to_proc, which continues to amaze me with its flexibility.

Daniel