From: Robert Klemme Date: 2010-10-24T03:05:13+09:00 Subject: Re: No key set in openstruct ? On 23.10.2010 19:16, jney wrote: > Is there a cleaner way to check if no field have been set than the > following code ? > >>>> o = OpenStruct.new > => # >>>> o.inspect == "#" > => true >>>> o.one_field = true > => true >>>> o.inspect == "#" > => false >>>> o.delete_field 'one_field' > => nil >>>> o.inspect == "#" > => true I'd consider this a tad cleaner - although it is not really rock solid: irb(main):015:0> x.methods - x.class.instance_methods => [:foo, :foo=] irb(main):016:0> x = OpenStruct.new => # irb(main):017:0> x.foo = 1 => 1 irb(main):018:0> x.methods - x.class.instance_methods => [:foo, :foo=] Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/