Skip to content

Instantly share code, notes, and snippets.

@a-chernykh
Last active September 8, 2015 22:04
Show Gist options
  • Save a-chernykh/474238c142442ef9914d to your computer and use it in GitHub Desktop.
Save a-chernykh/474238c142442ef9914d to your computer and use it in GitHub Desktop.
Interview test task
class Base
def initialize(attrs={})
# implement this
end
def self.find(id)
# implements this
end
def self.db
Database.new
end
def save
# implement this
end
# implement attribute getters
# implement attribute setters
end
class Book < Base
end
class Database
def select(id)
# returns hash or nil
end
def insert(attrs)
# inserts data into DB, returns id
end
def update(id, attrs)
# updates record with given id
end
end
book = Book.new(title: 'Lord of the Rings', pages: 500)
book.save
book = Book.find(10)
puts book.title
book.title = 'Another title'
book.save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment