From: non.dmitriy@... Date: 2018-02-20T15:24:23+00:00 Subject: [ruby-core:85698] [Ruby trunk Feature#14498] Class#to_proc Issue #14498 has been updated by Nondv (Dmitriy Non). Hanmac (Hans Mackowiak) wrote: > Duplicate of #4910 > > PS: might be a bit more complicated in C, > but i would like this: > > ~~~ruby > proc { |*args, **keyargs| self.new(*args, **keyargs) } > ~~~ > > so it works with keyargs too Hi! It's not really a duplicate since there is a different suggestion. I have written PR in C based on `Hash#to_proc` definition ---------------------------------------- Feature #14498: Class#to_proc https://bugs.ruby-lang.org/issues/14498#change-70502 * 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: ```ruby 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 ``` Here's the pull request: https://github.com/ruby/ruby/pull/1821 -- https://bugs.ruby-lang.org/ Unsubscribe: