Issue #15955 has been updated by mame (Yusuke Endoh).

File umethod_apply.patch added

Hi @nelhage and @darkdimius :-)

I'm attaching a patch for `UnboundMethod#apply(obj, *args, &blk)` as a shortcut to `.bind(obj).call(*args, &blk)` without allocation of a Method object.

I have heard the same situation as Sorbet for `pp`.  `pp` calls `method` method against its arguments.  The intention is to call `Object#method`, but sometimes it is overridden with completely different behavior, e.g., `Net::HTTPGenericRequest#method`.  So `pp` is using the same hack: https://github.com/ruby/ruby/blob/master/lib/pp.rb#L92

So I agree with the proposal.  I'm unsure if the name `apply` is good or not.  I'd like to ask matz at the next dev-meeting.

----------------------------------------
Feature #15955: UnboundMethod#apply
https://bugs.ruby-lang.org/issues/15955#change-80928

* Author: nelhage (Nelson Elhage)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I'd love a way to apply an UnboundMethod to a receiver and list of args without having to first `bind` it. I've ended up using `UnboundMethod`s in some hot paths in my application due to our metaprogramming idioms, and the allocation from `.bind` is comparatively expensive.

I'd love `unbound_method.apply(obj, args¡Ä)` to be equivalent to `unbound_method.bind(obj).call(args¡Ä)` but without allocating the intermediate `Method`



---Files--------------------------------
umethod_apply.patch (5.01 KB)


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

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