From: Robert Klemme Date: 2009-08-24T15:25:05+09:00 Subject: Re: Stupid OpenStruct question On 24.08.2009 06:02, Terry Smith wrote: > got it > > ff = s.fields > > ff.each{|g| > puts s.instance_eval g > } > 1 > 2 > > Terry Smith wrote: >> Ok - I know how to get the fields of an Openstruct object like so >> >> class OpenStruct >> def fields >> @table.keys.map{|k| k.to_s} >> end >> end >> >> a = OpenStruc.new() >> a.foo = 1 >> a.bar = 2 >> >> a.fields -> ["foo", "bar"] >> >> Great - ok how do I WORK with these once I have them? Just a remark: if your processing is mainly bases on keys this way then a Hash might the better data structure. IMHO an OpenStruct is best used when you are lazy or do not know all the fields that you are going to use beforehand. I find this especially useful during development, you can stuff in more and more fields but maybe later change it to a regular class (or Struct generated class). Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/