From: Hee-Sob Park Date: 2001-03-29T18:40:05+09:00 Subject: [ruby-talk:13318] hash slice implementaion Hi, I'd like to use Perl's hash slice feature in Ruby. Here is my implemetation of hash slice. How about this code? class Hash alias old_get [] alias old_set []= def [](*a) if a.length==1 old_get(a[0]) else indexes(*a) end end def []=(*a) if a.length==2 old_set(*a) else left = a[0...-1] right = a[-1] right = [right] if right.type != Array left.each_index {|x| old_set(left[x],right[x]) } end end end h = Hash.new h['one','two','three'] = [1,2,3] h[1,2,3,4] = %w(a b c d) h[*%w(a b c d)] = ['a1','a2','a3','a4'] a,b = h['a','b'] c,d = h['one','three'] Park Hee-Sob