On Thu, Apr 28, 2011 at 7:16 PM, 7stud -- <bbxx789_05ss / yahoo.com> wrote:
> "Jes=FAs Gabriel y Gal=E1n" <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 =3D Struct.new :id,:timestamp
>>  =3D> K
>> ruby-1.8.7-p334 :002 > K[3,8]
>>  =3D> #<struct K id=3D3, timestamp=3D8>
>>
>> Jesus.
>
> Is there a hash anywhere in your code? How about this:

Yep, I know. How about this?

ruby-1.8.7-p334 :014 > h =3D {:id =3D> 3, :timestamp =3D> 6}
 =3D> {:timestamp=3D>6, :id=3D>3}
ruby-1.8.7-p334 :043 > K =3D Struct.new :id, :timestamp do
ruby-1.8.7-p334 :044 >     def self.from_hash h
ruby-1.8.7-p334 :045?>     self[*h.values_at(*K.members.map {|m| m.to_sym})=
]
ruby-1.8.7-p334 :046?>     end
ruby-1.8.7-p334 :047?>   end
 =3D> K
ruby-1.8.7-p334 :048 > K.from_hash h
 =3D> #<struct K id=3D3, timestamp=3D6>

Jesus.