-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path7.rb
More file actions
41 lines (28 loc) · 775 Bytes
/
7.rb
File metadata and controls
41 lines (28 loc) · 775 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
class Post
attr_reader :author, :title, :body, :comments
def initialize options
@author = options[:author]
@title = options[:title]
@body = options[:body]
@comments = options[:comments] || []
end
def insert_comment *comments #splat! muchas cosas se pueden hacer con esto
comments.each { |c| @comments << c }
end
end
class Comment
attr_reader :user, :body
def initialize options
@user = options[:user]
@body = options[:body]
end
end
post = Post.new author: 'Alfonso',
title: 'Lipsum',
body: 'My message goes here'
com1 = Comment.new user: 'Jeffrey Way',
body: 'Nice post, ill like it'
com2 = Comment.new user: 'Alfonso Pidal',
body: 'Hola Jeffrey!!'
post.insert_comment com1,com2
p post.inspect