Created
June 15, 2012 00:31
-
-
Save Pcushing/2933862 to your computer and use it in GitHub Desktop.
Andrew & Patrick tackle the Dictionary (class)
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 | |
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