Sha256: 66869ce7ec1d6c84696d581c4884263dd6e120bec5c82cde81249fc481e5ba17

Contents?: true

Size: 744 Bytes

Versions: 6

Compression:

Stored size: 744 Bytes

Contents

module CaptainHoog
  module Delegatable
    def self.included(base)
      base.class_eval do
        extend ClassMethods
        include InstanceMethods
      end
    end

    module ClassMethods
      def delegate_to(target_object)
        define_method :delegate_to do
          self.instance_variable_get("@#{target_object}")
        end
      end
    end

    module InstanceMethods

      def method_missing(method_name, *args, &block)
        if delegate_to.respond_to?(method_name)
          delegate_to.send(method_name, *args, &block)
        else
          super
        end
      end

      def respond_to_missing?(method_name, include_private=false)
        delegate_to.respond_to?(method_name) || super
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
captain_hoog-2.0.0 lib/captain_hoog/delegatable.rb
captain_hoog-1.1.1 lib/captain_hoog/delegatable.rb
captain_hoog-1.1.0 lib/captain_hoog/delegatable.rb
captain_hoog-1.0.2 lib/captain_hoog/delegatable.rb
captain_hoog-1.0.1 lib/captain_hoog/delegatable.rb
captain_hoog-1.0 lib/captain_hoog/delegatable.rb