As an output file in
Ruby Ruby has a variety of ways that make it simple to output a file, depending on what you want to do with the data already on file. There are also a number of methods to write to open the file. Here are some ways quite compact, including some shortcuts, on the edge of a file in Ruby .
Open and write the file in Ruby
Open the file you want to exit.
Use the method File.open and pass the file name and a “way of life.” The way of life should be “w” or “”
a. Using “w” will erase all data already on file. The use of “one”, attach the data you want to write to the file until the end of that data file .
Print Print
data format with the method printf. If you need to write a sequence of numbers or strings, and the method printf format strings are a powerful tool in Ruby a .
Choose from the many options that go beyond the simple printing of a string or integer. The argument of printing is called a “format string”. It consists of the string to be printed, with a number within the codes that will expand .
For example, using “This is a number:% d”, was printed the string “This is an issue: “And then a decimal number .
close the file
Close the file using the method of closing. Call the close method, or the file could not be closed: f = File.open ( “myfile.txt”, “r”) # … Do something with filef.close
Use a method to close the file automatically if there is no need to be open for long. The File.open method can take a block as an argument .
If you switch from a block, the file is closed automatically at the end of the block.
Featured Links:
Proven Money Maker At $9,547 A Day.
Burn The Fat - Top Selling Fat Loss Ebook Since 2003.
Have You Ever Stayed Awake at Night Stressing About Whether or Not Your Marriage Will Last ... And What You Can Possibly Do to Save It?
Scan your computer for hidden AdWare and Spyware, Remove them permanently.
Join the Internet revolution and start downloading free movies and more!
Internet Marketer Gets $87 Million in Google Pay-Per-Click Ads FREE! ... And Makes Over $314 Million as a Result! ...And Now He's Going to Give You This Same Secret for Next to Nothing!








Leave a comment
You must be logged in to post a comment.