From: merch-redmine@... Date: 2018-08-24T20:55:04+00:00 Subject: [ruby-core:88639] [Ruby trunk Feature#15024] Support block in Array#join Issue #15024 has been updated by jeremyevans0 (Jeremy Evans). For `%{a b c d}.join { |_,_,i| i.to_s } == "a0b1c2d"`, you could do: ~~~ ruby *a, l = %w{a b c d}; a.each.with_object('').with_index{|(v, str), i| str << v << i.to_s} << l ~~~ That definitely isn't as nice looking. I can see the benefit of having the block return the separator, but I'm not sure how common such a need is. It's fairly straightforward to build the string manually in the cases you would need a separate separator per pair of items. Could you share a practical example that would benefit from Array#join block support? ---------------------------------------- Feature #15024: Support block in Array#join https://bugs.ruby-lang.org/issues/15024#change-73697 * Author: graywolf (Gray Wolf) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- I think it could be handy to have block support in Array#join. For example ```ruby > puts %w{a b c d}.join { |_, _, i| i % 2 == 1 ? "\n" : ', ' } a, b c, d ``` not sure what arguments exactly the block should take, atm I'm thinking of ```ruby > %w{a b c d}.join { |before, after, i| puts "#{before}:#{after}:#{i}" } a:b:0 b:c:1 c:d:2 ``` Would appreciate some feedback before I try putting together patch for this. -- https://bugs.ruby-lang.org/ Unsubscribe: