Skip to content

Instantly share code, notes, and snippets.

@kennyt
Created October 27, 2012 09:45
Show Gist options
  • Save kennyt/3963802 to your computer and use it in GitHub Desktop.
Save kennyt/3963802 to your computer and use it in GitHub Desktop.
11_dictionary
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