Created
April 6, 2013 19:48
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_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