From: ES Date: 2005-05-18T13:14:32+09:00 Subject: Re: Help with facade pattern Daniel Berger wrote: > Hi all, > > Well, I *think* it's the facade pattern. Anyway, I'm trying to do > something like this: > > class Foo < String > def method_a > Bar.method_a(self) > end > def method_b > Bar.method_b(self) > end > end > > This is easy enough to do by hand for a few methods, but what if I have > many methods from Bar I want to use? > > I thought maybe there was a trick with Forwardable I could use, but I > don't see how. Any ideas on how to shortcut this? You left too quick :) You are looking at something like this: class Class def forward(mod, *methods) methods.each do |method| # Substitute mod with const_get(mod) if you want to use :ModName define_method(method) {|| mod.send(method, self)} end end end class A def A.foo(x) puts "A.foo: #{x}" end end class B forward A, :foo end B.new.foo # => A.foo > Regards, > > Dan E -- template void quack(duck& d) { d.quack(); }