Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/string-stats-rh.rb

Instance Method Summary collapse

Instance Method Details

#unique_word_countObject



12
13
14
# File 'lib/string-stats-rh.rb', line 12

def unique_word_count
  self.unique_words.length
end

#unique_wordsObject



8
9
10
# File 'lib/string-stats-rh.rb', line 8

def unique_words
  self.split(' ').uniq
end

#word_countObject



4
5
6
# File 'lib/string-stats-rh.rb', line 4

def word_count
  self.split(' ').length
end

#word_frequenciesObject



16
17
18
19
20
# File 'lib/string-stats-rh.rb', line 16

def word_frequencies
  frequency = Hash.new(0)
  self.split(' ').each { |word| frequency[word.to_sym] += 1 }
  frequency
end