class Markovian::Chain::Dictionary
Public Instance Methods
==(other)
click to toggle source
# File lib/markovian/chain/dictionary.rb, line 17 def ==(other) self.dictionary == other.dictionary end
[](key)
click to toggle source
# File lib/markovian/chain/dictionary.rb, line 8 def [](key) # Key could be a string or a Tokeneyes::Word object dictionary[key.to_s] end
inspect()
click to toggle source
We override this method to avoid spitting out every single element in the dictionary if this (or any object containing it) gets inspected. See stackoverflow.com/questions/5771339/emulate-default-objectinspect-output.
# File lib/markovian/chain/dictionary.rb, line 24 def inspect "#<#{self.class}:0x#{__id__.to_s(16)} @dictionary: #{dictionary.length} entries>" end
random_word()
click to toggle source
# File lib/markovian/chain/dictionary.rb, line 13 def random_word dictionary.keys.sample end
Protected Instance Methods
dictionary()
click to toggle source
# File lib/markovian/chain/dictionary.rb, line 30 def dictionary # We have to set the value of the hash in the block, otherwise it doesn't actually seem to # get saved properly. Default hash values behave weirdly in general. @dictionary ||= Hash.new {|hash, key| hash[key] = DictionaryEntry.new(key)} end