From: matthew@... Date: 2014-01-31T23:23:21+00:00 Subject: [ruby-core:60393] [ruby-trunk - Feature #8987] map/collect extension which handles arguments Issue #8987 has been updated by Matthew Kerwin. On Jan 31, 2014 6:20 PM, wrote: > > Actually I believe the most readable form would be > > `p [1,2,3,4].map{ 4 + _ } # when there is no |...|, set block params to _ ` > > Many blocks in realworld-code are so easy, that it is really a barrier to have to think about a name, and therefore one uses often non-verbose names like you used x. Where is the point in being forced to think of a name, when you don't set the name to something meaningful. I guess this was the idea why the to_proc convention was introduced. The problem with it is, that it is really limiting because you cannot use parameters (and the presence of a parameter doesn't necessarily make problems so complex to justify a name). I guess you can solve it by syntax or by convention. I've, personally, never had a pause when calling it 'x' or 'item', depending on the context. You could also develop the convention of: arr.map{|_| ... } My only problem with magic variables is that I can never remember when they get (re)assigned. It's particularly annoying in perl, because those guys never assign a variable when $_ will suffice. Matthew Kerwin ---------------------------------------- Feature #8987: map/collect extension which handles arguments https://bugs.ruby-lang.org/issues/8987#change-44866 * Author: So Wieso * Status: Open * Priority: Normal * Assignee: * Category: core * Target version: current: 2.2.0 ---------------------------------------- Please consider extending map/collect by allowing additional arguments to be passed to proc, like: A: [1,2,3,4].map :+, 4 and/or B: [1,2,3,4].map 4, &:+ => [5, 6, 7, 8] Variant A is probably more readable. Variant B is more versatile (allows arbitrary arguments to be passed to block). ---Files-------------------------------- mappi.rb (410 Bytes) -- http://bugs.ruby-lang.org/