From: Aaron Smith Date: 2007-03-11T00:53:15+09:00 Subject: Re: OpenStruct,, know what keys are set Thanks for all the input. Heres some testing: require 'ostruct' require 'benchmark' lady = OpenStruct.new 0.upto(100) do |i| eval("lady.cat#{i} = i") #puts eval("lady.cat#{i}") end Benchmark.bm do |x| x.report("Find all keys 1"){lady.methods(false).grep(/[^=]$/)} x.report("Find all keys 2"){lady.instance_variable_get("@table").keys} x.report("Find all keys 3"){lady.keys_added} end #puts "\n" + lady.methods(false).grep(/[^=]$/).to_s #puts "\n" + lady.instance_variable_get("@table").keys.to_s #puts "\n" + lady.keys_added #this is always nil. OUTPUT: user system total real Find all keys 1 1.130000 0.050000 1.180000 ( 1.185657) Find all keys 2 0.020000 0.000000 0.020000 ( 0.019773) Find all keys 3 0.000000 0.000000 0.000000 ( 0.000020) Results speak for themselves. -- Posted via http://www.ruby-forum.com/.