From: James Edward Gray II Date: 2007-01-20T05:58:12+09:00 Subject: Re: Declaring instance variables dynamically On Jan 19, 2007, at 2:42 PM, gwtmp01@mac.com wrote: > > On Jan 19, 2007, at 3:05 PM, Alex Schearer wrote: > >> Thanks for the feedback. I am in fact trying to do what openstrtuct >> allows despite any confusing language I might have employed. I was >> curious whether there was any way to do so without employing a hash >> table -- that isn't to say that PHP doesn't employ a hash table >> with its >> objects. Now I know, and let me just also say thank you for the >> lengthy >> response. I invariably find it more useful when more experienced >> members of the community explain/tell me something than when they >> point >> me to a reference document, though that is still more useful than no >> response at all. > > Well, it is certainly possible to roll your own class that > uses instance variables instead of the hash table. You can use > method_missing to capture calls to object.x and object.x= and then > set or get the matching instance variables. > > I'll bet this has been done many times before. Maybe in facets? > Trans? It's called OpenStruct and it is included in Ruby's standard library. James Edward Gray II