From: Gavin Sinclair Date: 2004-08-24T13:58:22+09:00 Subject: Re: OpenStruct respond_to? problem On Tuesday, August 24, 2004, 1:03:40 PM, Austin wrote: > On Tue, 24 Aug 2004 09:59:15 +0900, Jamis Buck wrote: >> I blindly assumed that OpenStruct would handle respond_to? properly, but >> I'm seeing the following behavior: >> >> o = OpenStruct.new( :type_id => "string" ) >> p o.type_id #-> "string" >> p o.respond_to?( :type_id ) #-> false >> >> Is this the correct behavior for OpenStruct, or should this be reported >> as a bug? > I think that OpenStruct uses #method_missing. Indeed it does. If respond_to? is to work, you'd need to implement it. Utterly untested: class OpenStruct def respond_to?(sym) super or @table.key?(sym.to_sym) end end There's probably several problems with OpenStruct along these lines. I don't think #hash is implemented, for example. Gavin