Quick Ruby help

SSSnail

Lifer
Nov 29, 2006
17,461
82
86
I need some quick help with a Ruby script, nothing fancy but I'm stuck as I'm not a scripting guy by any means.

Essentially, I need the script to open a file, do some stuff, and then write the result to a file.

File.open ("file.txt") do |file|
do_stuff > result
print result.to_jason , "\n"
...
File.new("new.txt", "w")

I'm stuck at the ... part. Help!
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,250
3,845
75
Sorry, I can't quite figure out what you're trying to do there. "do_stuff" isn't very descriptive. [thread=2069847]Please use code tags[/thread]! Also, did you mean "to_json"?
 

SSSnail

Lifer
Nov 29, 2006
17,461
82
86
Sorry, I can't quite figure out what you're trying to do there. "do_stuff" isn't very descriptive. [thread=2069847]Please use code tags[/thread]! Also, did you mean "to_json"?

Oh, I'm just trying to instead of doing this rubyscript.rb > text.txt from cmd, run the script and it would output the text.txt file.

out_file = File.new("text.txt", "w")
out_file.write e.to_json + "\n"

would get me the file, but for some reasons it only output one entry, instead of all the entries in a file. And yes, to_json, not jason...hehe.