Skip to content

Instantly share code, notes, and snippets.

@andreychernih andreychernih/base.rb
Last active Sep 8, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.