Skip to content

Instantly share code, notes, and snippets.

@zachgersh
Created April 6, 2013 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zachgersh/5327371 to your computer and use it in GitHub Desktop.
Save zachgersh/5327371 to your computer and use it in GitHub Desktop.
class Dictionary
attr_reader :entries
def initialize
@entries = Hash.new
end
def add(add_text)
if add_text.class == Hash
add_text.each do |key, value|
@entries[key] = value
end
else
@entries[add_text] = nil
end
end
def keywords
@entries.keys.sort
end
def include?(key)
@entries.include?(key)
end
def find(key)
@entries.select {|k| k.include?(key)}
end
def printable
sorted = @entries.sort
temp_string = ""
sorted.each do |array_cell|
temp_string += "[#{array_cell[0]}] \"#{array_cell[1]}\"\n"
end
temp_string.strip
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment