Sha256: cd09bce2d18897d6b431e50ea87cf72bc9ad95a238c83351248f3d5c6768acda
Contents?: true
Size: 1.12 KB
Versions: 15
Compression:
Stored size: 1.12 KB
Contents
# A thing is destroyed if a number of lives has been passed. # module Lives extend Trait # TODO def revive! # # Prints an amount of information on these capabilities. # manual <<-MANUAL Defines: lives <some trait> Example: lives 10 Call kill! to remove a live. Override killed! to exhibit behaviour. MANUAL def self.included target_class target_class.extend IncludeMethods end module IncludeMethods # Define the amount of lives in the class. # def lives amount include InstanceMethods class_inheritable_accessor :prototype_lives self.prototype_lives = amount hook = lambda { self.lives = self.class.prototype_lives } InitializerHooks.register self, &hook end end module InstanceMethods attr_accessor :lives # Does three things: # * Deduct 1 live. # * Check to see if the amount is 0. # * Calls #destroy! if yes. # def killed! end def kill! self.lives -= 1 killed! if self.lives > 0 destroy! if self.lives == 0 end end end
Version data entries
15 entries across 15 versions & 1 rubygems