From: "alexeymuranov (Alexey Muranov)" Date: 2013-09-01T05:32:03+09:00 Subject: [ruby-core:56950] [ruby-trunk - Feature #6721] Object#yield_self Issue #6721 has been updated by alexeymuranov (Alexey Muranov). =begin Another idea for the name: (({Object#cast})), by analogy with typecasting or cast iron. Iron (an object) is poured into a mold (a proc or a block). class Object def cast(*args, &block) if block.nil? p = args.shift if p.is_a?(Proc) p[self, *args] else raise 'The first argument of Object#cast should be a Proc, unless a block form is used.' end else if args.empty? block[self] else raise 'Object#cast does not accept arguments together with a block.' end end end end 2.cast {|x| x**3 } # => 8 p = proc {|x, y| x**y } 2.cast(p, 4) # => 16 =end ---------------------------------------- Feature #6721: Object#yield_self https://bugs.ruby-lang.org/issues/6721#change-41509 Author: alexeymuranov (Alexey Muranov) Status: Open Priority: Normal Assignee: matz (Yukihiro Matsumoto) 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/