On 9/7/07, Marc Heiler <shevegen / linuxmail.org> wrote: > Hi > > Please no "redesign" proposal as in "do not try to do this > at all" - I really want to know if the following is possible, > and if it is, how. And if it is not, I can't try anyway > and have to rethink/redesign the approach to it _anyway_ :) > Thanks. > > I spent a little time digging through ruby-prototype, dl/struct, > evil.rb but given my lack of knowledge, ended up more > confused than enlightened. > > A somewhat lengthy explanation follows, but please don't tie > this too much to my specific problem at hand, in actual > practice I am more interested in how to have an object > of class X become an object of Class Y instead > > __________________________________________________________________ > > I have a general class, a button. This class will be responsible for > providing all required datasets to "become" a "specialized" button. > > With "specialized", I really mean a Button for i.e. a specific widget > set, like Qt. So that the user can work with a Qt button, or a > gtk button, or a FXRuby button and so on, but without the need to > care about the internals and widget-specific problems. > This is just to help the user focus on one language aspect (describing > his widget once, and only once) and then have code help him to > realize the rest. (In reality i'd later plan to separate the > layout even more to use "classes" similar to Cascading Style Sheets > for "grouped" styling, but ignore this for now please) > > The moment the user needs this "prototype widget" to be specific (our > button in this case, but there will be more abstract widget sets in the > future, if this works) he "converts" it to a certain toolset. > For example, this button becomes FXButton.new now. > > The reason for the abstraction is because it makes no sense > to restrict yourself to one specific widget set, if the logic itself > is pretty much the same in all toolsets (Clicking, mouse moving, > actions, > especially colours and padding etc..) and should be easily > accessible to a human reader too without the need to pick a > widget-specific solution, like gtk rc_files. > > Enough pretext, now the question! :) > > How can I convert my object "foobar" of "class Button" > > foobar = Button.new > > to become a "real" Gtk::Button for instance? > > Inside class Button I can not modify self, so I wonder if > there is any option at all to convert to the Gtk::Button. > I can create a new Gtk::Button inside class Button easily, > with all the required data, but it seems my created object > is never able to leave its class Button state. At best > it can only do a "return Gtk::Button" in the end. > > I am glad for any ideas and help. > -- > Posted via http://www.ruby-forum.com/. > > Changing the class of the Button object won't work. I would suggest just storing the new object in an instance variable in the Button object. -- Chris Carter concentrationstudios.com brynmawrcs.com