From: Dan Schmidt Date: 2001-03-30T00:40:08+09:00 Subject: [ruby-talk:13327] Re: hash slice implementaion matz@zetabits.com (Yukihiro Matsumoto) writes: | In message "[ruby-talk:13318] hash slice implementaion" | on 01/03/29, "Hee-Sob Park" writes: | | | | I'd like to use Perl's hash slice feature in Ruby. | | Here is my implemetation of hash slice. | | How about this code? | | It's interesting. The only reason hash#[] does not accept multiple | argument for slice is consistency with array, which uses [] argument | differently. If consensus is made, I'd like to merge it. But I | doubt. I made the suggestion recently that Array#[] and Hash#[] exhibit slicing behavior when the argument is an Array (or any Enumerable, maybe? Array#[](aRange) already works like this). So you would need an extra pair of brackets if you specify the array argument explicitly. Would this eliminate ambiguities? e.g., h = {} h[1] = 'a' h[2] = 'b' h[[1, 2]] => ['a', 'b'] a = [2, 1] h[a] = ['b', 'a'] It would mean that you couldn't use Arrays as keys to Hashes, but that seems like a bad idea anyway. -- http://www.dfan.org