Module: Cosensee::Delegatable

Included in:
PageStore, Project, WebContentGenerator
Defined in:
lib/cosensee/delegatable.rb

Overview

Add delegate method that delegate method calls to another object

Usage:

“‘ruby class Foo

extend Delegatable

def initialize(bar)
  @bar = bar
end

attr_reader :bar

delegate :buz, :baz, to: :bar

end “‘

This will define `buz` and `baz` method that call `bar.buz` and `bar.baz` respectively.

Instance Method Summary collapse

Instance Method Details

#delegate(*methods, to:) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/cosensee/delegatable.rb', line 24

def delegate(*methods, to:)
  methods.each do |method|
    define_method(method) do |*args, **kargs, &block|
      target = send(to)
      target.public_send(method, *args, **kargs, &block)
    end
  end
end