Sha256: 7028a95fa079c662b00c8fbb2dbc04fd487b378d2d2584b6aaa002169a02cd58

Contents?: true

Size: 560 Bytes

Versions: 4

Compression:

Stored size: 560 Bytes

Contents

# encoding: utf-8

# Include this module to strategy superclass
module RubyExts
  module StrategyMixin
    class << self
      attribute :strategies, Array.new

      def register
        self.strategies.push(self)
      end

      def find(*args)
        self.strategies.find { |strategy| strategy.match?(*args) }
      end
    end

    def match?(*args)
      raise "This method must be redefined in subclasses"
    end

    def run(*args)
      raise "This method must be redefined in subclasses"
    end

    # define setup method if you need it
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubyexts-0.3.pre lib/rubyexts/mixins/strategy.rb
rubyexts-0.0.2.1 lib/rubyexts/mixins/strategy.rb
rubyexts-0.0.2 lib/rubyexts/mixins/strategy.rb
rubyexts-0.1.pre lib/rubyexts/mixins/strategy.rb