Sha256: 62109bf8de20dfa6851be9730fdacbc7fc95cd16b54c5bd1e16e7e2c98972ff9

Contents?: true

Size: 977 Bytes

Versions: 19

Compression:

Stored size: 977 Bytes

Contents

module Mutant
  # A simple delegator with opinions
  module Delegator
    # Class level mixins
    module ClassMethods

    private

      # Create delegators to object
      #
      # @return [undefined]
      #
      # @api private
      #
      def delegate(*names)
        names.each(&method(:define_delegator))
      end

      # Create delegator to object
      #
      # @param [Symbol] name
      #
      # @return [undefined]
      #
      # @api private
      #
      def define_delegator(name)
        fail "method #{name} already defined" if instance_methods.include?(name)
        define_method(name) do
          object.public_send(name)
        end
        private name
      end

    end # ClassMethods

    # Hook called when module is included
    #
    # @param [Class,Module] host
    #
    # @return [undefined]
    #
    # @api private
    #
    def self.included(host)
      super

      host.extend(ClassMethods)
    end

  end # Delegator
end # Mutant

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
mutant-0.8.0 lib/mutant/delegator.rb
mutant-0.7.9 lib/mutant/delegator.rb
mutant-0.7.8 lib/mutant/delegator.rb
mutant-0.7.7 lib/mutant/delegator.rb
mutant-0.7.6 lib/mutant/delegator.rb
mutant-0.7.5 lib/mutant/delegator.rb
mutant-0.7.4 lib/mutant/delegator.rb
mutant-0.7.3 lib/mutant/delegator.rb
mutant-0.7.2 lib/mutant/delegator.rb
mutant-0.7.1 lib/mutant/delegator.rb
mutant-0.6.7 lib/mutant/delegator.rb
mutant-0.6.6 lib/mutant/delegator.rb
mutant-0.6.5 lib/mutant/delegator.rb
mutant-0.6.4 lib/mutant/delegator.rb
mutant-0.6.3 lib/mutant/delegator.rb
mutant-0.6.2 lib/mutant/delegator.rb
mutant-0.6.0 lib/mutant/delegator.rb
mutant-0.5.26 lib/mutant/delegator.rb
mutant-0.5.25 lib/mutant/delegator.rb