Skip to content

Instantly share code, notes, and snippets.

@jessieay
Created June 16, 2012 00:00
Show Gist options
  • Save jessieay/2939278 to your computer and use it in GitHub Desktop.
Save jessieay/2939278 to your computer and use it in GitHub Desktop.
Dictionaryyyyyy
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