From: 7stud -- Date: 2011-04-29T02:16:04+09:00 Subject: Re: Initialize Struct from Hash "Jesús Gabriel y Galán" wrote in post #995567: > On Thu, Apr 28, 2011 at 7:00 PM, Brian Candler > 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] > => # > > 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) -- Posted via http://www.ruby-forum.com/.