Forum: Ruby Output Source Code to Text document

Eb3ca21728af8ccbbe4991603157596d?d=identicon&s=25 Bill Manning (dbm4891)
on 2013-10-29 18:19
So I have a simple ruby script I created for an assignment and my
professor wants us to output the original source code to a formatted
text file.

As of now I have a started separate script opening the assignment as
read then I create a new file with writing privileges. But I'm not sure
what I do next.

All files are in the same project folder.




File.open("Assignment.rb", "r") do |file|
  new_file = File.new("sourcecode.txt", "w+")
  while line = file.gets
    new_file.puts
  end
end


I'm not entirely sure where to go to next,any help would greatly be
appreciated!
14b5582046b4e7b24ab69b7886a35868?d=identicon&s=25 Joel Pearson (virtuoso)
on 2013-10-29 18:24
Not sure what you mean by a "formatted" text file, but if you want to
copy the contents of one file to another...

File.write('output.txt', File.read('input.txt'))

Of course, if you're going down that road you could use File or
Fileutils' copy or copy_file method.
Eb3ca21728af8ccbbe4991603157596d?d=identicon&s=25 Bill Manning (dbm4891)
on 2013-10-29 18:29
Ah, that's it. I was over complicating the task. That helped a lot.

Thank you!
15000f55138ae94b0f362ed7c625461a?d=identicon&s=25 unknown (Guest)
on 2013-10-29 19:05
(Received via mailing list)
Am 29.10.2013 18:19, schrieb Bill Manning:
> So I have a simple ruby script I created for an assignment and my
> professor wants us to output the original source code to a formatted
> text file.
>
> As of now I have a started separate script opening the assignment as
> read then I create a new file with writing privileges. But I'm not sure
> what I do next.

That doesn't make *any* sense to me. You could copy the file using the
file manager of your operating system or the command line, but what for?

The Ruby source code essentially is a text file.
But what do you mean by a "formatted text file"???
6cd5090839b1021f85bd329e1ed09264?d=identicon&s=25 Andrew B. (andrew_b19)
on 2013-11-02 10:03
> The Ruby source code essentially is a text file.
> But what do you mean by a "formatted text file"???

What? You don't write your Ruby code in Microsoft Word?
15000f55138ae94b0f362ed7c625461a?d=identicon&s=25 unknown (Guest)
on 2013-11-03 17:10
(Received via mailing list)
Am 02.11.2013 10:03, schrieb Andrew B.:
>> The Ruby source code essentially is a text file.
>> But what do you mean by a "formatted text file"???
>
> What? You don't write your Ruby code in Microsoft Word?

Not yet... but as soon as I get Word running under Wine on my
Linux machine I'll switch. Word is so much easier to use than vim...

:)

Regards,
Marcus
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.