From: "alexeymuranov (Alexey Muranov)" Date: 2012-11-10T19:19:41+09:00 Subject: [ruby-core:49192] [ruby-trunk - Feature #6721] Object#yield_self Issue #6721 has been updated by alexeymuranov (Alexey Muranov). =begin After commenting on #6284, i have a new proposition for this method's name: (({Object#^})). Also, i suggest to allow it to take a block, a proc, a lambda, or a symbol. I think this will not conflict with existing uses of #^, however the classes that implement it for certain argument types should not forget to call (({super})) if the argument type is not recognized by them. For example: # Formatting a string: format_as_title = lambda { |str| "Title: #{ str.strip.capitalize }" } title = " something to be a title " ^ format_as_title # instead of `format_as_title.call(" something to be a title ")` # Squareing the 2: four = 2 ^ { |x| x*x } # instead of `four = 2�**2` # Converting a string to an integer: five = "5" ^ :to_i # instead of `five = "5".to_i` This is consistent with a rare mathematical notation for function application: sometimes instead of "f(x)", the "exponential" notation "x^f" is used. This would also open a door to compose lambdas from left to right, if the majority decides so (this is being discussed in #6284) =end ---------------------------------------- Feature #6721: Object#yield_self https://bugs.ruby-lang.org/issues/6721#change-32742 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/