From: itsme213 Date: 2005-01-10T10:26:22+09:00 Subject: Re: List assignment syntax "Florian Gross" wrote in message news:34a0olF483uq0U2@individual.net... > Zsban Ambrus wrote: > > > I'm a little dissatisfied with the list assignment syntax of ruby. > > On an example: > > > > irb(main):001:0> a = [2, [3, 5], 8] > > => [2, [3, 5], 8] > > > > This works: > > > > irb(main):002:0> x, (y, ), z = a > > => [2, [3, 5], 8] > > Personally, I would like being able to assign to nil in that case. I've > seen "_" been used as a throw away assignment target, but that's just > not as expressive as "nil", IMHO. Is there not a more general pattern-match + assign variables, much like regular expressions do a pattern-match + assign? Would it be nice to be able to pick up several pattern-matched variables concisely for all ruby objects? list_pattern = list # like example above # instead of: x = list[0]; y = list[1][0], z = list[2] hash_pattern = hash # instead of: x = hash[:a]; y = hash[:b][:c]; z = hash[:d] obj_pattern = obj # instead of: x = obj.a; y = obj.b.c; z = obj.d And compose them: [x, hash_pattern, z] = list_with_item_hash_items And use them in parameter lists, for loops, etc. def f ( event_name, (start, end), response ); .... end for x, (y,), z in list_with_item_list_items do ... end What do other Ruby-ists think?