From: Joey Zhou Date: 2011-05-25T23:20:10+09:00 Subject: [ruby-core:36465] [Ruby 1.9 - Feature #4772] Hash#add_keys Issue #4772 has been updated by Joey Zhou. Rodrigo Rosenfeld Rosas wrote: > Actually, as already noticed here, this could be just: > > ['a', 'b', 'c'].each {|k| hash[k]} # You don't need to assign to it. Well, it is very obscure here, easy to be confused. 1) hash = Hash.new {|h,k| k.succ } 2) hash = Hash.new {|h,k| h[k] = k.succ } 1) and 2) are different, 2) will actually create any key/value pair the hash ever seen a key, but 1) will not, it needs an assignment. Joey ---------------------------------------- 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