<commit_before>module Hangman
  class Word
    attr_reader :result

    def initialize
      @word_to_guess = random_word
      @result = '_' * @word_to_guess.size
    end

    def contain?(letter)
      @word_to_guess.include?(letter)
    end

    def add_to_result(letter)
      @word_to_guess.split('').each_with_index { |e, i| result[i] = letter if e == letter }
      result
    end

    private

    def random_word
      dictionary = File.read('./5desk.txt').split
      dictionary.select { |word| word.size.between?(5, 12) }.sample.downcase
    end
  end
end
<commit_msg>finish Word class<commit_after>module Hangman
  class Word
    attr_reader :result, :incorrect_letters

    def initialize
      @word_to_guess = random_word
      @result = '_' * @word_to_guess.size
      @incorrect_letters = []
    end

    def play(letter)
      @word_to_guess.include?(letter) ? add_to_result(letter) : add_to_incorrect_letters(letter)
      feedback
    end

    private

    def feedback
      "#{result.split('').join(' ')}\tincorrect: #{incorrect_letters.sort.join(', ')}"
    end

    def add_to_result(letter)
      @word_to_guess.split('').each_with_index { |e, i| result[i] = letter if e == letter }
    end

    def add_to_incorrect_letters(letter)
      incorrect_letters.push(letter)
    end

    def random_word
      dictionary = File.read('./5desk.txt').split
      dictionary.select { |word| word.size.between?(5, 12) }.sample.downcase
    end
  end
end

{'fraction_non_alphanumeric': 0.11504424778761062, 'fraction_numerical': 0.005445881552076242, 'mean_word_length': 2.888888888888889, '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': '6050664', 'n_tokens_mistral': 520, 'n_tokens_neox': 503, 'n_words': 100}