Sha256: 8f696d06a6d268202d57b0f2c9c1653c9a7be87f922cd1ca97837de3f494a218

Contents?: true

Size: 934 Bytes

Versions: 11

Compression:

Stored size: 934 Bytes

Contents

# encoding: utf-8

module TTY
  # A mixin to allow delegetable methods to be added
  module Delegatable
    # Create delegator for each specified method
    #
    # @example
    #   delegatable_method :source, :method
    #
    # @param [Symbol] source
    #
    # @param [Array] methods
    #
    # @return [self]
    #
    # @api public
    def delegatable_method(source, *methods)
      methods.each do |method|
        define_delegatable_method(source, method)
      end
      self
    end

    private

    # Create a delegator method for the method name
    #
    # @param [Symbol] source
    #
    # @param [Symbol] method name
    #
    # @return [undefined]
    #
    # @api private
    def define_delegatable_method(source, method)
      class_eval <<-RUBY, __FILE__, __LINE__ + 1
        def #{method}(*args, &block)
          #{source}.#{method}(*args, &block)
        end
      RUBY
    end
  end # Delegatable
end # TTY

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
tty-0.5.0 lib/tty/support/delegatable.rb
tty-0.4.0 lib/tty/support/delegatable.rb
tty-0.3.2 lib/tty/support/delegatable.rb
tty-0.3.1 lib/tty/support/delegatable.rb
tty-0.3.0 lib/tty/support/delegatable.rb
tty-0.2.1 lib/tty/support/delegatable.rb
tty-0.2.0 lib/tty/support/delegatable.rb
tty-0.1.3 lib/tty/support/delegatable.rb
tty-0.1.2 lib/tty/support/delegatable.rb
tty-0.1.1 lib/tty/support/delegatable.rb
tty-0.1.0 lib/tty/support/delegatable.rb