"Jess Gabriel y Galn" <jgabrielygalan / gmail.com> wrote in post #995567:
> On Thu, Apr 28, 2011 at 7:00 PM, Brian Candler <b.candler / pobox.com>
> wrote:
>>  self
>> (I'm talking about real Struct here, not OpenStruct etc)
> ruby-1.8.7-p334 :001 > K = Struct.new :id,:timestamp
>  => K
> ruby-1.8.7-p334 :002 > K[3,8]
>  => #<struct K id=3, timestamp=8>
>
> Jesus.

Is there a hash anywhere in your code? How about this:


K1 = Struct.new :foo, :bar

class MyClass < K1
  def initialize(hash)
    super(*hash.values_at(:foo, :bar) )
  end
end

puts MyClass.new(bar: 456, foo: 123)


(stolen from: http://stackoverflow.com/questions/2680523/dry-ruby-initialization-with-hash-argument)