From: Brian Candler Date: 2011-12-08T18:20:47+09:00 Subject: Re: Using any trick to omit () in constant lookup? What you are asking for is possible, simply by overriding the new method: class GTKButton; end class OldButton; end class Button def self.new(*args,&blk) if $use_gtk GTKButton.new(*args,&blk) else OldButton.new(*args,&blk) end end end $use_gtk = true puts Button.new.class This is unusual, and it may surprise users of your library to call Button.new and actually receive an object of a different class. But it's not unreasonable - I did this in a ruby-ip library once, so that IP.new(...) would return either an IP::V4 object or an IP::V6 object depending on the argument format. Gunther's solution is the more general and flexible one. It allows your Button wrapper to be composed of one or more other objects, which can be changed dynamically as the object runs. A method call x(a,b,c) on your wrapper object can then be mapped to whatever calls are required on the underlying objects, e.g. @obj1.y(a) and @obj2.z(c,b) I suspect you will want to do both: return different classes for each type of Button, and within those classes, map the method calls to an underlying object or objects. This will allow your Button facade objects to implement the same API calls and translate them to what is actually required. This is of course only part of the story. If you want your UI toolkit to be interchangeable then it will have to expose the same programming model and data structures, and unifying that across the various underlying libraries may be more difficult than you expect. -- Posted via http://www.ruby-forum.com/.