Created
October 27, 2012 09:45
-
-
Save kennyt/3963802 to your computer and use it in GitHub Desktop.
11_dictionary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Dictionary | |
def initialize | |
@dictionary = {} | |
end | |
def entries | |
@dictionary | |
end | |
def add (entry) | |
if entry.length > 1 | |
return @dictionary.store(entry, nil) | |
end | |
key = entry.keys.join('') | |
value = entry.values.join('') | |
@dictionary.store(key, value) | |
end | |
def keywords | |
@dictionary.keys.sort | |
end | |
def include? (word) | |
@dictionary.keys.include?(word) ? true : false | |
end | |
def find (word) | |
answer = {} | |
@dictionary.each_key do |key| | |
key.include?(word) ? answer.store(key, @dictionary[key]) : nil | |
end | |
answer | |
end | |
def printable | |
answer = '' | |
@dictionary.keys.sort.each do |key, value| | |
answer << ("[#{key}]" + " \"#{@dictionary[key]}\"\n" ) | |
end | |
answer.chomp | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment