Skip to content

Instantly share code, notes, and snippets.

@bswinnerton
Last active August 29, 2015 13:58
Show Gist options
  • Select an option

  • Save bswinnerton/10429797 to your computer and use it in GitHub Desktop.

Select an option

Save bswinnerton/10429797 to your computer and use it in GitHub Desktop.
require_relative 'lib/user'
require_relative 'lib/post'
#require 'pry'
brooks = User.new('Brooks', 'brooks@ga.co')
Post.new('Cat takes over the world', 'asdfasdfas', brooks)
Post.new('colbert', 'asdf', brooks)
Post.new('asdf', 'qwer', brooks)
Post.all.each do |post|
puts post
puts
end
#binding.pry
class Post
attr_accessor :title, :body, :author
@@posts = []
def initialize(title, body, author)
@title = title
@body = body
@author = author
@@posts << self
end
def self.all
@@posts
end
def to_s
"Title: #{@title}\nBody: #{@body}"
end
end
class User
attr_accessor :name, :email
def initialize(name, email)
@name = name
@email = email
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment