Project

General

Profile

Actions

Feature #10879

open

UnboundMethod#to_proc

Added by Gondolin (Damien Robert) almost 10 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:68213]

Description

Since unbound methods from modules can now be bound to any object, I use them a lot.
I think it would be very natural to be able to convert them to Proc:

module UnboundMethod
  def to_proc
    return lambda do |obj,*args,&b|
      self.bind(obj).call(*args,&b)
    end
  end
end

This would allow things like

module Foo
  def foo
    self+"foo"
  end
end
["bar","baz"].map(&Foo.instance_method(:foo)) => ["barfoo", "bazfoo"]

No data to display

Actions

Also available in: Atom PDF

Like0