Issue #6721 has been updated by headius (Charles Nutter).


It occurs to me #apply is used in some other languages to refer to the elements of a collection rather than to the collection itself.

[1,2,3].apply {|n| puts n}

Did we ever decide if the #self method would be added? If it were, it would be simple to have it take a block:

four = 2.self {|n| n * n}

That would make #self basically be #ergo as defined by Facets.

Worth noting that you can get nearly as concise syntax today, albeit in reverse order:

four = ->{|n| n * n}.(2)
----------------------------------------
Feature #6721: Object#yield_self
https://bugs.ruby-lang.org/issues/6721#change-33823

Author: alexeymuranov (Alexey Muranov)
Status: Open
Priority: Normal
Assignee: 
Category: core
Target version: next minor


=begin
I think the following method is missing from Ruby:

 class Object
   def yield_self(*args)
     yield(self, *args)
   end
 end

I do not know a good use case, but it looks very natural to me.  It can be used in method chains.

What do you think?  Is there an alternative?
=end



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