Sha256: 3add2011dcdb94c876390781a3998530ac1139900ca482b99f9d3af34452ba3b
Contents?: true
Size: 1.46 KB
Versions: 3
Compression:
Stored size: 1.46 KB
Contents
module Scorpion # A concrete implementation of a Scorpion used to hunt down food for a {Scorpion::King}. # @see Scorpion class Hunter include Scorpion # ============================================================================ # @!group Attributes # # @return [Scorpion::HuntingMap] map of {Prey} and how to create instances. attr_reader :hunting_map protected :hunting_map # @return [Scorpion] parent scorpion to deferr hunting to on missing prey. attr_reader :parent private :parent # # @!endgroup Attributes def initialize( parent = nil, &block ) @parent = parent @hunting_map = Scorpion::HuntingMap.new( self ) prepare &block if block_given? end # Prepare the scorpion for hunting. # @see HuntingMap#chart def prepare( &block ) hunting_map.chart &block end # @see Scorpion#hunt def hunt_by_traits( contract, traits = nil, *args, &block ) unless prey = hunting_map.find( contract, traits ) return parent.hunt_by_traits contract, traits if parent prey = Scorpion::Prey::ClassPrey.new( contract, nil ) if contract.is_a?( Class ) && traits.blank? unsuccessful_hunt( contract, traits ) unless prey end prey.fetch self, *args, &block end # @see Scorpion#replicate def replicate replica = self.class.new self replica.hunting_map.replicate_from( hunting_map ) replica end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
scorpion-ioc-0.3.1 | lib/scorpion/hunter.rb |
scorpion-ioc-0.3.0 | lib/scorpion/hunter.rb |
scorpion-ioc-0.2.0 | lib/scorpion/hunter.rb |