[ruby-core:85694] [Ruby trunk Feature#14498] Class#to_proc

From: non.dmitriy@...
Date: 2018-02-20 15:01:19 UTC
List: ruby-core #85694
Issue #14498 has been reported by Nondv (Dmitriy Non).

----------------------------------------
Feature #14498: Class#to_proc
https://bugs.ruby-lang.org/issues/14498

* Author: Nondv (Dmitriy Non)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Hello!

I was creating a list of class instances via `some_list.map { |e| SomeClass.new(e) }` and wondered if there's a `Class#to_proc` to make possible doing `some_list.map(&SomeClass)`.
Well, there is not.

Basically, this is what I suggest:

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

class Dog
  attr_reader :name

  def initialize(name)
    @name = name
  end
end

names = %w[Lucky Pluto Balto]
names.map(&Dog) # map names to dogs
```



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next