From: Logan Capaldo Date: 2006-06-02T17:12:08+09:00 Subject: Re: An alternative to the class Foo < Struct.new(vars) idiom and SuperStruct On Jun 1, 2006, at 11:13 PM, Hal Fulton wrote: > Mauricio Fernandez wrote: >> On Thu, Jun 01, 2006 at 09:33:29PM +0900, Jeff Rose wrote: >>> I'm sold. This will be great for easily defining event types in >>> EventMachine. Why the complicated default argument values >>> though? For simple cases how about just using hash syntax: >>> >>> MyClass = SuperClass.new(:a => 2, :b => 3) >> The problem with this is that it makes positional arguments >> impossible, since >> the Hash doesn't preserve the order; maybe > > [snip] > > That's another example of why I would like a data structure > that 1) had a convenient notation for literals and 2) was > "like" a Hash, but ordered. > > > Hal > > This is why I kind of like how in Perl => is just a synonym for comma (it is in ruby too, at least for Hash literals, the problem being that it forces a hash literal). then def f(*args) args end f(1 => 2) #=> [1,2] if you wanted a hash you could just do def g(*args) Hash[ *args ] end Of course this takes away your ability to write things like f(1, 2, :option => value) but you could still do f(1, 2, {:option => value }) I dunno. Maybe just use caller and some evil read the file in again (or SCRIPT_LINES__ to find out what order they called it in).