def markov_update_count!(grams, word, gram_size)
      word.chars.each_cons(gram_size + 1) do |gram|
        l = gram[0..gram_size - 1].join
        r = gram[gram_size]

        unless l.empty? || r.empty? || line_ending?(r)
          grams[l] = {} if grams[l].nil?
          grams[l][r] = grams[l][r].nil? ? 1 : grams[l][r] += 1
        end
      end
    end
def markov_update_count!(grams, word, gram_size)
      word.chars.each_cons(gram_size + 1) do |gram|
        l = gram[0..gram_size - 1].join
        r = gram[gram_size]

        unless l.empty? || r.empty? || line_ending?(r)
          grams[l] = {} if grams[l].nil?
          grams[l][r] = grams[l][r].nil? ? 1 : grams[l][r] += 1
        end
      end
    end
Given a database of `grams` and a `word`, and the `gram_size` (the
 maximum n-gram size we want to compute), update the `grams` database with
 entries for each n-gram combination starting at `gram_size` and going
 down to 1.