i want to have a class that can support multiple sets of methods, based
on what the client requests. so far i have written the following python
code. it’s ugly/not elegant and i haven’t managed to come up with a less
ugly ruby version 
<<EOF
class C:
def foo(self):
print "foo"
def bar1(self):
print "bar version 1"
def bar2(self, arg):
print “bar version 2, arg =”, arg
def facet(self, whichFacet=1):
if whichFacet == 1:
return C_facet1(self)
elif whichFacet == 2:
return C_facet2(self)
return
class C_facet1:
def init(self, c):
self.foo = c.foo
self.bar = c.bar1
class C_facet2:
def init(self, c):
self.foo = c.foo
self.bar = c.bar2
c1 = C().facet(1) # client1 picks interface1
c1.foo() # prints "foo"
c1.bar() # prints “bar version 1”
c2 = C().facet(2) # client2 picks interface2
c2.foo() # prints "foo"
c2.bar(123) # prints "bar version 2, arg = 123"
EOF
if a client wants interface 1, then she will get the methods foo and bar
(which is actually C#bar1). if he picks interface 2, then she will get
the methods foo and bar (which is actually C#bar2). for all she cares,
she just wants to know/deal with a single [versatile] class, C. and from
that single class, she can pick several sets of features/interfaces she
needs/wants.
i know that, in ruby, modules are usually used for things like this, but
in my case many of the method names are the same so i don’t think
modules are approriate for this. for example, interface1 consists of
foo, bar, baz, abc, and abd. interface2 consists of foo, bar, baz, bab,
bac. in most of the cases all of the interfaces provide the same set of
features, just in a different style or different revision.
any pointers of how i might do something like this in ruby?
···
–
dave