From: Andrew Grimm Date: 2011-09-21T09:25:45+09:00 Subject: [ruby-core:39647] [Ruby 1.9 - Feature #4830] Provide Default Variables for Array#each and other iterators Issue #4830 has been updated by Andrew Grimm. =begin For a simple case, such as (({some_array.map { foo(it) }.select { bar(it) }.each { baz(it) }})) You can do (({some_array.map(&method(:foo)).select(&method(:bar)).each(&method(:bar))})) instead. > PS: Since $dollar variables are rarely used anyway, lets transform them all into special variables :D Maybe we could migrate global variables into katakana, so we'd have local_variable, CONSTANT, $special_variables and ������! =end ---------------------------------------- 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