Subject: Creating a struct from an array of symbols


I’d like to create a Struct[1] from an array containing symbols representing
the attributes of the Struct but can’t get it to work:

arr = [:attr1, :attr2, :attr3]

s =
# => TypeError: no implicit conversion of Array into String

I’ve tried different conversions (to_s, etc.) and OpenStruct[2], too. Even
though the latter is supposed to work dynamically it needs a hash and does not
work with my array of symbols:

os =
# => NoMethodError: undefined method `each_pair’ for [:attr1, :attr2,

os =
# => NoMethodError: undefined method `[]' for nil:NilClass


Any ideas on how I can feed in my array of symbols into or an

Many thanks!



Unsubscribe: <mailto:[email protected]?subject=unsubscribe>

Programming list archiving by: Enterprise Git Hosting