From: Rodrigo Rosenfeld Rosas Date: 2011-05-25T22:44:30+09:00 Subject: [ruby-core:36460] [Ruby 1.9 - Feature #4772] Hash#add_keys Issue #4772 has been updated by Rodrigo Rosenfeld Rosas. > In recent version, if I want to do the same thing, the code may be: > > hash = Hash.new {|h,k| k + k.succ} > ["a","b","c"].each do |key| > hash[key] = hash[key] # this kind of assignment is somewhat odd > end Actually, as already noticed here, this could be just: ['a', 'b', 'c'].each {|k| hash[k]} # You don't need to assign to it. But I like your suggestion anyway... ---------------------------------------- Feature #4772: Hash#add_keys http://redmine.ruby-lang.org/issues/4772 Author: Joey Zhou Status: Open Priority: Normal Assignee: Category: Target version: Hi, do you want to add a new method Hash#add_keys in a new version? hash = Hash.new {|h,k| k.to_s + "foo" } hash.add_keys("a","b","c") # the value is hash's default obj or proc value If there's a word list file, I want to make the words keys of a hash, maybe I can write: hash = {} hash.add_keys(*open("file").readlines.map(&:chomp)) -- http://redmine.ruby-lang.org