Created
June 16, 2012 00:00
-
-
Save jessieay/2939278 to your computer and use it in GitHub Desktop.
Dictionaryyyyyy
This file contains hidden or 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 | |
attr_accessor :this_dictionary | |
def initialize | |
this_dictionary = {} | |
@this_dictionary = this_dictionary | |
end | |
def entries | |
@this_dictionary | |
end | |
def add(entry) | |
if entry.is_a?(Hash) | |
@this_dictionary.merge!(entry) | |
else | |
@this_dictionary[entry] = nil | |
end | |
end | |
def keywords | |
@this_dictionary.keys.sort! | |
end | |
def include?(test_key) | |
@this_dictionary.include?(test_key) | |
end | |
def find(entry) | |
if @this_dictionary.empty? | |
return "" | |
else | |
@this_dictionary.select do |key| | |
key.start_with?(entry) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment