From: Lazaridis Ilias Date: 2011-06-06T16:32:49+09:00 Subject: [ruby-core:36781] [Ruby 1.9 - Feature #4830] Provide Default Variables for Array#each and other iterators Issue #4830 has been updated by Lazaridis Ilias. [please, if possible, delete the non-relevant quoted message in your reply. You can still do this via http://redmine.ruby-lang.org/issues/4830] Rodrigo Rosenfeld Rosas wrote: > Sorry, forgot to say that for hashes this becomes: > > [key_name: 'value', another_key: 'another_value'].each{ println > "${it.key}: ${it.value}"} [...] > Em 05-06-2011 15:56, Rodrigo Rosenfeld Rosas escreveu: > > I would just like to point it out that in Groovy, one can write either: > > > > [1, 2].each{ println it } [...] "it" is not speakable. "with each it" "for each it" where "item" or "value" is speakable "with each item" or "with each value" "for each item" or "for each value" ---------------------------------------- Feature #4830: Provide Default Variables for Array#each and other iterators http://redmine.ruby-lang.org/issues/4830 Author: Lazaridis Ilias Status: Assigned Priority: Low Assignee: Yukihiro Matsumoto Category: core Target version: for arrays: use "item" by default for hashes: use "key" and "value" by default names = ["Jane", "Michele", "Isabella"] names.each { |name| print name, "\n" } names.each { print item, "\n" } contact = {name:"Jane", phone:"1234567"} contact.each { |key, value| print key, ": ", value, "\n"} contact.each { print key, ": ", value, "\n"} - The benefits are: * more compact code (without loosing clarity of the code). * no repetitions ("names, name, name") in a one-liner with {} block This extension does not break any existent behaviour. -- http://redmine.ruby-lang.org