I have created two classes, Blog and Post, try to create an array of Post, in Blog, shows me the following error: "undefined method` push 'for {}: Hash "
How I can do to keep in the Array?
class Blog
def initialize
@post = {}
end
def addPost (newPost)
#Here I try to add an object blog, post an array of objects
@post.push(newPost)
end
end
class Post
def initialize title, date, text
@title = title
@date = date
@text = text
end
def printPost
puts "#{@title} \n #{@date} \n ****************** \n #{@text}"
end
end
myBlog = Blog.new
firstPost = Post.new("First Post", "21/12/2014", "This is my first post on my first blog")
secondPost = Post.new("Second Post", "11/10/2015", "This is my seocond post on my first blog")
myBlog.addPost(firstPost)
myBlog.addPost(secondPost)
Thanks
Array.. But you didn't give a small amount of time to read the Ruby Array API.. That's not good. :(pushon an instance ofHash(i.e, sending the methodpushto an instance of the classHash). The error message says that the classHashdoesn't have an instance methodpush.