<commit_before># Die Class 2: Arbitrary Symbols


# I worked on this challenge [by myself, with: ].
# I spent [#] hours on this challenge.

# Pseudocode
=begin

Initialize
  Input: Array of strings
  Output: Die Object
  Steps:
    IF the input array's length is equal to 0
      Raise an Argument Error indicating input cannot be an empty array
    ELSE
      Set the variable @sides to be equal to the length of the input array
      Set the variable @labels to be equal to the input array itself
    END

Sides
  Input: None
  Output: Integer
  Steps:
    RETURN the variable @sides

Roll
  Input: None
  Output: A string
  Steps:
    Select a random number from 0 to @sides - 1
    Use that number to select a string from the array @labels using index notation
    RETURN the selected string.

=end
# Initial Solution

# class Die
#   def initialize(labels)
#     (labels.length == 0) ? (raise ArgumentError.new("Cannot input an empty array.")) : (@sides = labels.length; @labels = labels)
#   end

#   def sides
#     @sides
#   end

#   def roll
#     return @labels[rand(0..@sides-1)]
#   end
# end



# Refactored Solution

class Die

  def initialize(labels)
    if labels.length == 0 
      raise ArgumentError.new("Cannot input an empty array.")
    else
      @sides = labels.length
      @labels = labels
    end
  end

  def sides
    @sides
  end

  def roll
    return @labels.sample
  end
end






# Reflection

=begin

What were the main differences between this die class and the last one you created in terms of implementation? Did you need to change much logic to get this to work?
  Not much of the logic had to be changed really. Other than making @sides
  dependent on length and storing an extra variable, the implementation was<commit_msg>Minor mod to my_solution.rb<commit_after># Die Class 2: Arbitrary Symbols


# I worked on this challenge [by myself, with: ].
# I spent [#] hours on this challenge.

# Pseudocode
=begin

Initialize
  Input: Array of strings
  Output: Die Object
  Steps:
    IF the input array's length is equal to 0
      Raise an Argument Error indicating input cannot be an empty array
    ELSE
      Set the variable @sides to be equal to the length of the input array
      Set the variable @labels to be equal to the input array itself
    END

Sides
  Input: None
  Output: Integer
  Steps:
    RETURN the variable @sides

Roll
  Input: None
  Output: A string
  Steps:
    Select a random number from 0 to @sides - 1
    Use that number to select a string from the array @labels using index notation
    RETURN the selected string.

=end
# Initial Solution

# class Die
#   def initialize(labels)
#     (labels.length == 0) ? (raise ArgumentError.new("Cannot input an empty array.")) : (@sides = labels.length; @labels = labels)
#   end

#   def sides
#     @sides
#   end

#   def roll
#     return @labels[rand(0..@sides-1)]
#   end
# end



# Refactored Solution

class Die

  def initialize(labels)
    if labels.length == 0 
      raise ArgumentError.new("Cannot input an empty array.")
    else
      @sides = labels.length
      @labels = labels
    end
  end

  attr_reader :sides

  def roll
    return @labels.sample
  end
end






# Reflection

=begin

What were the main differences between this die class and the last one you created in terms of implementation? Did you need to change much logic to get this to work?
  Not much of the logic had to be changed really. Other than making @sides
  dependent on length and storing an extra variable, the implementation was
{'fraction_non_alphanumeric': 0.06246466930469192, 'fraction_numerical': 0.0045223289994347085, 'mean_word_length': 2.9018743109151046, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6786749', 'n_tokens_mistral': 1064, 'n_tokens_neox': 1014, 'n_words': 488}