-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpeerchallenge1.rb
More file actions
40 lines (31 loc) · 827 Bytes
/
Copy pathpeerchallenge1.rb
File metadata and controls
40 lines (31 loc) · 827 Bytes
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
# Problem
## There are two writers. How many words can each writer write and how many words in the book in total? ##
# Solution
class Book
def initialize(book_name)
@book_name = book_name
@total_word_count = 0
end
attr_accessor :book_name
def receieve_words(words)
@total_word_count = words + @total_word_count
puts "Book has total words of: #{@total_word_count}"
end
end
class Writer
def initialize(author_name)
@author_name = author_name
@word_count = 0
end
attr_accessor :author_name, :word_count
def write_words(words, book)
book.receieve_words(words)
@word_count = words + @word_count
puts "Author has written: #{@word_count}"
end
end
x = Book.new("awesome")
y = Writer.new("rowling")
z = Writer.new("tolkien")
y.write_words(50, x)
z.write_words(50, x)