Skip to content

Instantly share code, notes, and snippets.

@Pcushing
Created June 15, 2012 00:31
Show Gist options
  • Save Pcushing/2933862 to your computer and use it in GitHub Desktop.
Save Pcushing/2933862 to your computer and use it in GitHub Desktop.
Andrew & Patrick tackle the Dictionary (class)
class Dictionary
def initialize
@my_hash = {}
end
def add(word_hash)
if word_hash.is_a?Hash
@my_hash.merge!(word_hash)
else
@my_hash[word_hash] = nil
end
end
def include?(word)
@my_hash.has_key?(word)
end
def keywords
@my_hash.keys.sort
end
def entries
@my_hash
end
def find(word)
@my_hash.select { |k,v| k =~ /^#{ word }/ }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment