Hassan Schroeder wrote in post #1074525:
> On Mon, Sep 3, 2012 at 7:57 PM, Dave Castellano <[email protected]>
> wrote:
>
>> I am placing an undefined method after file.write("Hello"). Crashes the
>> program and leaves the file so I can open it - its empty...
>
> Interesting programming style :-)
>
> Personally, I'd close the file so it gets written to disk, and then look
> at it. FWIW.
>
> --
> Hassan Schroeder ------------------------ [email protected]
> http://about.me/hassanschroeder
> twitter: @hassan
Yes, I'm learning to program on my own... I don't believe anyone would
pay for my work :-)
Thanks, you were right - it is writing to the file and I can see it
after closing.
Can I follow with one last question...
I have written a method, saved it in a table, and this is what I am
writing to the temp file. Can I require the file and then call the
method (getting the returned arguments) from the temp file as it is
saved as a .rb file? eg...
def format_q_gen
file = Tempfile.new([generator_file_name, ".rb"],
"./lib/generators")
file.write(question)
returned_question = generator_file_name # Calls the method in the
tempfile
formatted = {
question: q["question_1"],
correct_answer_letter: "a"
}
file.close
file.unlink
end
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit https://groups.google.com/groups/opt_out.