From: "Mauricio Fernández" Date: 2003-06-18T18:45:15+09:00 Subject: switching multiple interfaces of an object I've been toying with some code that does what I believe people asking for #unextend normally need. It allows one object to have several different interfaces (possibly overlapping, ie. with the same method names) and to let the client select which one to use as in A = a.new a.foo a.bar 1,2,3 a.with_interface(:extended) do a.foo('arguments','possibly','required','with','this','interface') a.bar 1,2,3 end the class definition would be something like class A include InterfaceSwitching def initialize set_interface :normal end def foo puts "A#foo" end def bar(*args) puts "A#bar: #{args.inspect}" end def_interface :normal, :foo, :bar def foo(*args) puts "A(extended)#foo, ignoring args" end def bar(*args) r = args.map { |i| i * 2 } puts "A(extended)#bar: #{args.inspect} => #{r.inspect}" end def_interface :extended, :foo, :bar end of course, it could be used this way too: class A include InterfaceSwitching include SomeModule1 def_interface :somemodule1, *SomeModule1.instance_methods include SomeModule2 def_interface :somemodule2, *SomeModule2.instance_methods end Is this useful at all? I thought of this as I was writing on the Adaptor pattern. I consider the above to be a "generalized" (dynamic) adaptor. -- _ _ | |__ __ _| |_ ___ _ __ ___ __ _ _ __ | '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ | |_) | (_| | |_\__ \ | | | | | (_| | | | | |_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_| Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com How should I know if it works? That's what beta testers are for. I only coded it. -- Attributed to Linus Torvalds, somewhere in a posting