From: Joey Zhou Date: 2011-05-25T22:38:54+09:00 Subject: [ruby-core:36459] [Ruby 1.9 - Feature #4772] Hash#add_keys Issue #4772 has been updated by Joey Zhou. Adam Prescott wrote: > On Tue, May 24, 2011 at 9:36 AM, Joey Zhou wrote: > > > 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 default proc, I can't see why you'd need to create the keys > like this. If you did want to, can you not just use > > keys.each { |k| hash[keys] } > > ? > > For instance: > > open("file").readlines.map(&:chomp).each { |k| hash[k] } This doesn't create the actual key/value pair, the way seems not explicit, I'm afraid. ---------------------------------------- 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