From: David Alan Black Date: 2001-09-11T12:18:22+09:00 Subject: [ruby-talk:21053] Re: @aHash{A..Z} = (0..25); Hello -- On Tue, 11 Sep 2001, Dat Nguyen wrote: > How to write the following Perl code in Ruby: > > @aHash{A..Z} = (0..25); One possibility, drawn from some Ruby Behaviors experiments: class Hash alias :oldset :[]= def []=(ks,vs) ks.to_a.each_with_index do |k,i| oldset(k,vs.to_a[i]) end end end c = {} c['A'..'Z'] = 0..25 (One of my main incentives for working on Ruby Behaviors has always been to get more back-and-forth going between arrays (or ranges) and hashes.) David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav