From: "marcandre (Marc-Andre Lafortune)" Date: 2012-11-20T03:37:35+09:00 Subject: [ruby-core:49606] [ruby-trunk - Feature #7388] Object#embed Issue #7388 has been updated by marcandre (Marc-Andre Lafortune). mame (Yusuke Endoh) wrote: > My personal opinion: the method name will matter. I'd even say that `embed` is wrong. I would like to know of a good example of use case. I often succumb to the temptation of writing more complex code to avoid creating a local var, but that doesn't always make for better code. The example given in the github PR was: [ 1, 2, 3, 4].select{|x| x.odd?}.embed{|x| {:total => x.count, :data => x}}... I feel the following is clearer: odd_nbs = [ 1, 2, 3, 4].select{|x| x.odd?} {:total => odd_nbs.count, :data => odd_nbs}... Until I see a good use case (and a good method name is found), I'm -1 for this. ---------------------------------------- Feature #7388: Object#embed https://bugs.ruby-lang.org/issues/7388#change-33122 Author: zzak (Zachary Scott) Status: Assigned Priority: Normal Assignee: matz (Yukihiro Matsumoto) Category: core Target version: next minor =begin From github: https://github.com/ruby/ruby/pull/67 Add Object#embed which works like tap but returns the block's value This avoids breaking from method chains in many cases. I don't see any other way to do this without this method. Can someone confirm pull request are a valid way of submitting patches ? I cannot register on the mailing list for some reason, it seems to be broken. Example: (({[ 1, 2, 3, 4].select{|x| x.odd?}.embed{|x| {:total => x.count, :data => x}}})) =end -- http://bugs.ruby-lang.org/