title: Ruby forwarding to a object returned by accessor method
body: <p>I have a class with roughly the following structure:</p>
  <pre><code>class X
    def initialize
      @container = Container.new
      ....
    end
    def store
      @container.get_store
    end
    def f
      store.f
    end
    def g
      store.g
    end
    def h
      store.h
    end
    ....
  end
  </code></pre>
  <p>As can be seen, I have a couple of methods, which simply &quot;forward&quot; to <em>store</em>, only that <em>store</em> is not an instance variable, but the result of a parameterless method. Is there a compact way to implement this forwarding? If <code>store</code> would always return the identical object, I could do something like this:</p>
  <pre><code>class X
    extend Forwardable
    def initialize
      container = Container.new
      @store = container.the_store
    end
    def_delegator :@store, .f, :g, :h
  end
  </code></pre>
  <p>but I can't rely on this; <code>@container.the_store</code> may change during the lifetime of the instance. One alternative I considered is something like</p>
  <pre><code>class X
    [:f,:g,:h].each do |meth_sym|
      define_method(meth_sym) do |*args|
        store.public_send(meth_sym, *args)
      end
    end
    def store
      @container.get_store
    end
  end
  </code></pre>
  <p>but this looks clumsy. Can anymody suggest a different solution for my problem?</p>