From: lasitha Date: 2009-03-02T14:20:14+09:00 Subject: Re: Delegating class methods On Mon, Mar 2, 2009 at 2:27 AM, Michael Malone wrote: > On Mon, Mar 2, 2009 at 2:03 AM, abc wrote: >> >> how would you forward calls from class methods to a class atribute? >> [...] >> >> I have to delegate a fairly large number of calls to an attribute. [...] > > class Klass > extend Forwardable > def_delegators :@object :method1, :method2, :method3 > > def initialize > @object = SomeKlass.new > end > end No, that would forward to an instance variable and only work with Klass instances. If the OP doesn't mind using a singleton class variable instead of a class variable [1], then we can still use forwardable: class Foo @hash = {} class << self extend Forwardable def_delegators :@hash, :[], :[]=, :size end end Foo[:bar] = 'baz' Foo.size #=> 1 Solidarity, lasitha [1] Generally a good idea anyway, right?