Here's the beginning of an email posting app that I'm working on in Ruby. Creating an article works fine, but how I am lost to retrieve one. I want my paragraph.gate method to return an article object. But the only way to do this is to write all the article attributes Are there any better ways of doing what I really do not want to do?
is required 'date' is required 'focus' is required 'module' is required News class articable attr_reader: subject,: body, created :: directory, : File_name, file:,: author, attr_writer: subject, body: created,: directory, file_name, file :: author def initialize (author, topic, body) @topic = topic @body = body @ author = author @ Created = DateTime.now () @directory = 'archive /' + @ created.strftime ('% y /% m') + '/' @file_name = @ created.strftime ('% h-% m-% s' ) @ File = @documentary + @ file file File.makedirs (@ directory) till file.directory? (@directory) if! File.file? (@ File) @article = File.new (@file, 'w', 0777) @ Articles. Print "# {@ subject} \ n # {@ author} \ n # {@ body}" @ article Close () end and df graph. Gate (path) # ??? End of End
I think the problem here is that you have to initialize Using the method to record files in the file system, when you
article
) To come back with an article object, that is also the initialize method; That's why it's probably confusing; You seem to be explaining two things in one method.
To make it easy, you have a different continuation
(save) method> method. initialize
I'm sure you have good reasons to do this on a file system instead of a database, but I can not help feeling that it has read about the active record pattern, whether it It's (if you decide to use a database) or just
Comments
Post a Comment