Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Deletion Implementation
class Database
def initialize
@count = Hash.new(0)
@db = Hash.new()
end
# CRUD COMMANDS
def set(key, value)
@db[key] = value
@count[value] += 1
return nil
end
def get(key)
@db.fetch(key, "NULL")
end
def count(value)
@count.fetch(value, 0)
end
def delete(key)
value = @db[key]
if value
@db.delete(key)
@count[value] -= 1
return nil
else
return "That key isn't in the database!"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.