<commit_before># 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<commit_msg>+ lives code simplified<commit_after># 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
    target_class.send :include, InstanceMethods
  end
  
  module IncludeMethods
    
    # Define the amount of lives in the class.
    #
    def lives amount
      InitializerHooks.register self do
        self.lives = amount
      end
      attr_reader :lives # override the default
    end
    
  end
  
  module InstanceMethods
    
    attr_writer :lives
    
    def lives
      3
    end
    
    # 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
{'fraction_non_alphanumeric': 0.05670103092783505, 'fraction_numerical': 0.006443298969072165, 'mean_word_length': 1.9406565656565657, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2723360', 'n_tokens_mistral': 740, 'n_tokens_neox': 720, 'n_words': 253}