-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblog.rb
84 lines (65 loc) · 1.19 KB
/
blog.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
class Blog
@@blog_posts = []
@@total_blog_posts = 0
def self.all
@@blog_posts
end
def self.add (blog)
@@blog_posts << blog
@@total_blog_posts += 1
end
def self.publish
@@blog_posts.each do |post|
puts "Title:\n #{post.title}"
puts "Content:\n #{post.content}"
puts "Publish Date:\n #{post.publish_date}"
puts "Created By:\n #{post.author}"
end
end
end
class BlogPost < Blog
def self.create
post = new
puts "Name your blog post:"
post.title = gets.chomp
puts "Write your blog post"
post.content = gets.chomp
post.publish_date = Time.now
puts "What is the author's name?"
post.author = gets.chomp
post.save
puts "Do you want to create another blog post? [Y/N]"
create if gets.chomp.downcase == "y"
end
def title
@title
end
def title=(title)
@title = title
end
def content
@content
end
def content=(content)
@content = content
end
def publish_date
@publish_date
end
def publish_date=(publish_date)
@publish_date = publish_date
end
def author
@author
end
def author=(author)
@author = author
end
def save
BlogPost.add(self)
end
end
BlogPost.create
blog_posts = BlogPost.all
puts blog_posts.inspect
BlogPost.publish