Class: String

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

Instance Method Summary collapse

Instance Method Details

#unique_word_countObject



26
27
28
# File 'lib/string-stats-ah.rb', line 26

def unique_word_count
	self.unique_words.length
end

#unique_wordsObject



19
20
21
22
23
24
# File 'lib/string-stats-ah.rb', line 19

def unique_words
	hash = self.word_frequencies
	arr = []
	hash.each_key { |key| arr << key.to_s }
	return arr
end

#word_countObject



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

def word_count
	arr = self.split(" ")
	return arr.length
end

#word_frequenciesObject



8
9
10
11
12
13
14
15
16
# File 'lib/string-stats-ah.rb', line 8

def word_frequencies
	arr = self.split(" ")
	arr.sort!
	histogram = Hash.new(0)
	arr.each do |word|
		histogram[word.downcase.to_sym] += 1
	end
	return histogram
end