Class: WordScramble::LetterFrequency
- Inherits:
-
Object
- Object
- WordScramble::LetterFrequency
- Defined in:
- lib/word_scramble/letter_frequency.rb
Instance Attribute Summary collapse
-
#frequency_hash ⇒ Object
readonly
Returns the value of attribute frequency_hash.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(str) ⇒ LetterFrequency
constructor
A new instance of LetterFrequency.
Constructor Details
#initialize(str) ⇒ LetterFrequency
Returns a new instance of LetterFrequency.
4 5 6 7 8 9 10 11 12 |
# File 'lib/word_scramble/letter_frequency.rb', line 4 def initialize(str) @length = str.length @frequency_hash = {} str.downcase.each_char do |c| @frequency_hash[c] ||= 0 @frequency_hash[c] += 1 end end |
Instance Attribute Details
#frequency_hash ⇒ Object (readonly)
Returns the value of attribute frequency_hash.
2 3 4 |
# File 'lib/word_scramble/letter_frequency.rb', line 2 def frequency_hash @frequency_hash end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
2 3 4 |
# File 'lib/word_scramble/letter_frequency.rb', line 2 def length @length end |
Instance Method Details
#==(other) ⇒ Object
14 15 16 |
# File 'lib/word_scramble/letter_frequency.rb', line 14 def ==(other) other.is_a?(WordScramble::LetterFrequency) and other.frequency_hash == @frequency_hash end |