From: "Hal E. Fulton" Date: 2003-05-14T11:59:55+09:00 Subject: Re: OpenStruct (was: [OO design] Objects VS Datastructures) ----- Original Message ----- From: "Mark Wilson" To: "ruby-talk ML" Sent: Tuesday, May 13, 2003 9:47 PM Subject: Re: OpenStruct (was: [OO design] Objects VS Datastructures) > > On Tuesday, May 13, 2003, at 10:43 PM, Jim Weirich wrote: > > > On Tue, 2003-05-13 at 17:33, Dave Thomas wrote: > > > >> Contact = OpenStruct > >> c = Contact.new > >> c.name = "Dave Thomas" > >> c.tel = "555 1212" > > > > OpenStruct. Cool. I hadn't seen this before. > > > > [snip] > > Me too! I didn't notice at first the difference from the earlier Struct > class. > > This is a nice improvement over Struct, which required defining the > attributes in an initial Struct statement. It's an alternative, anyway. I like the Struct in that it documents the layout of the structure when we initialize it. But if you're not populating all values for every object, or if (interesting case) you add unforeseen fields via a data file at runtime, then OpenStruct could be a great thing. BTW, it's not in the core (at least not in my 1.7.3 -- I know I should be ashamed of myself for not being on the bleeding edge). So require "ostruct" to get it (those of you who were wondering). It's a nice tribute to the simplicity of Ruby and the power of the method_missing technique (only 55 lines, and could have been done in fewer). Hal