From: Jonathan Leighton Date: 2006-01-09T09:03:50+09:00 Subject: Re: Passing a hash of args On Mon, 2006-01-09 at 08:01 +0900, James Edward Gray II wrote: > Well, Hashes are unordered by definition, but as long as we declare > an order it's doable: > > >> time = { > ?> :year => 2003, > ?> :month => 03, > ?> :day => 24 > >> } > => {:month=>3, :year=>2003, :day=>24} > >> Time.local(*time.values_at(:year, :month, :day)) > => Mon Mar 24 00:00:00 CST 2003 Cool. Thanks everyone. I didn't realise you could do *myvar when calling a method as well as when defining them. I was basically looking for a way to do the following (which I've managed to solve without use of a hash): class Time UNITS = [ :year, :month, :day, :hour, :min, :sec, :usec ] def to_precision(unit) args = [] 0.upto(UNITS.index(unit)) { |unit| args << method(UNITS[unit]).call } Time.local(*args) end end Is that a sensible way to do it? Cheers -- Jonathan Leighton http://turnipspatch.com/ | http://jonathanleighton.com/ | http://digital-proof.org/