Sha256: 6ed63d055c6570f89f4fe5cc94d58da5b795d5ea4d3eb0f475f25885999be4bd

Contents?: true

Size: 698 Bytes

Versions: 1

Compression:

Stored size: 698 Bytes

Contents

# frozen_string_literal: true

module Cosensee
  # 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.
  module Delegatable
    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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cosensee-0.8.0 lib/cosensee/delegatable.rb