<commit_before>require_relative 'randomizers'
require 'delegate'

module Tabletop
  class Pool < DelegateClass(Array)
    include Comparable
    
    # requires one parameter, which can be either of 
    #  - an array of Die objects
    #  - a string of d-notation
    def initialize(init_dice)
      return super(init_dice) if init_dice.instance_of?(Array)
      d_groups = init_dice.split
      dice = []
      d_groups.each do |d_notation|
        number, sides = d_notation.split('d')
        number = number.to_i
        number += 1 if number == 0
        if sides.to_i > 0
          number.times { dice << Die.new(sides.to_i)}
        elsif sides == "F"
          number.times {dice << FudgeDie.new}
        end
      end
      super(dice)
    end
    
    # Behavior depends on the class of what is passed to it.
    # Numeric::  returns the sum of the operand and the values of all dice in the receiving pool
    # Pool:: returns a new pool with copies of all the dice in both operands
    # AnythingElse:: raises an ArgumentError
    def +(operand)
      # if the operator is a pool, or an array only of Die objects...
      if operand.instance_of?(Pool) or (operand.instance_of?(Array) and !(operand.detect{|obj| !(obj.instance_of?(Die))}))
        new_union(operand)
      elsif operand.kind_of? Numeric
        sum + operand
      else
        raise ArgumentError, "Cannot add operand of class #{operand.class}"
      end<commit_msg>forget this delegate nonsense<commit_after>require_relative 'randomizers'

module Tabletop
  class Pool < Array
    include Comparable
    
    # requires one parameter, which can be either of 
    #  - an array of Die objects
    #  - a string of d-notation
    def initialize(init_dice)
      return super(init_dice) if init_dice.kind_of?(Array)
      d_groups = init_dice.split
      dice = []
      d_groups.each do |d_notation|
        number, sides = d_notation.split('d')
        number = number.to_i
        number += 1 if number == 0
        if sides.to_i > 0
          number.times { dice << Die.new(sides.to_i)}
        elsif sides == "F"
          number.times {dice << FudgeDie.new}
        end
      end
      super(dice)
    end
    
    # Behavior depends on the class of what is passed to it.
    # Numeric::  returns the sum of the operand and the values of all dice in the receiving pool
    # Pool:: returns a new pool with copies of all the dice in both operands
    # AnythingElse:: raises an ArgumentError
    def +(operand)
      # if the operator is a pool, or an array only of Die objects...
      if operand.instance_of?(Pool) or (operand.instance_of?(Array) and !(operand.detect{|obj| !(obj.instance_of?(Die))}))
        new_union(operand)
      elsif operand.kind_of? Numeric
        sum + operand
      else
        raise ArgumentError, "Cannot add operand of class #{operand.class}"
      end
{'fraction_non_alphanumeric': 0.08577405857740586, 'fraction_numerical': 0.0020920502092050207, 'mean_word_length': 2.4400479616306954, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 5, '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': '5962741', 'n_tokens_mistral': 860, 'n_tokens_neox': 868, 'n_words': 302}