Where is the public class method File.read() defined? Which take a
file name as parameter, but what is in return? I have search all the
document and source code, just can't find the definition.
Could anyone point me to the source file? I really want to know,
thanks in advance.
Where is the public class method File.read() defined? Which take a
file name as parameter, but what is in return? I have search all the
document and source code, just can't find the definition.
Could anyone point me to the source file? I really want to know,
thanks in advance.
Where is the public class method File.read() defined? Which take a
file name as parameter, but what is in return? I have search all the
document and source code, just can't find the definition.
Could anyone point me to the source file? I really want to know,
thanks in advance.
Where is the public class method File.read() defined? Which take a
file name as parameter, but what is in return? I have search all the
document and source code, just can't find the definition.
Could anyone point me to the source file? I really want to know,
thanks in advance.
Try:
file_in = File.new("input_file","r")
file_in.each do |line|
Ruby methods normally return the last thing in the method.
File.read() will return the contents of the file.
As others said, it inherits from class IO
Many people just use IO.read() instead because of this.
you can go into the site ruby directory inside of the ruby directory (where you installed ruby) and open the File class files and read them.
···
On Sep 6, 2007, at 11:34 AM, Gregory Brown wrote:
On 9/6/07, optman <optman@gmail.com> wrote:
Where is the public class method File.read() defined? Which take a
file name as parameter, but what is in return? I have search all the
document and source code, just can't find the definition.
Could anyone point me to the source file? I really want to know,
thanks in advance.
if File.read() return the entire file content, what if sourceFile is a
large file?
···
On 9 7 , 1 24 , John Joyce <dangerwillrobinsondan...@gmail.com> wrote:
On Sep 6, 2007, at 11:34 AM, Gregory Brown wrote:
> On 9/6/07, optman <opt...@gmail.com> wrote:
>> Where is the public class method File.read() defined? Which take a
>> file name as parameter, but what is in return? I have search all the
>> document and source code, just can't find the definition.
>> Could anyone point me to the source file? I really want to know,
>> thanks in advance.
Ruby methods normally return the last thing in the method.
File.read() will return the contents of the file.
As others said, it inherits from class IO
Many people just use IO.read() instead because of this.
you can go into the site ruby directory inside of the ruby directory
(where you installed ruby) and open the File class files and read them.
Then you are in trouble if you use File.read(). From your example I
can don't know what the method #put does, but one might logically
surmise that its function is to put a string (the output of File.read)
into targetFile.
Reading a file into a string and then writing that string to a file is
not a good solution for large files. The module ::FileUtils contains a
method #cp which very efficiently (by ruby standards) copies one file
to another -- without requiring that the entire contents of the source
file be copied into memory first.
Rio (http://rio.rubyforge.org) will also copy a file without requiring
the source file being read into memory first:
rio('sourceFile') > rio('targetFile')
···
On Sep 6, 9:41 pm, optman <opt...@gmail.com> wrote:
On 9 7 , 1 24 , John Joyce <dangerwillrobinsondan...@gmail.com> > wrote:
I have seen a line of code like
put( File.read(sourceFile),targetFile)
if File.read() return the entire file content, what if sourceFile is a
large file?
Method #put is from Capistrano, which upload file to remote server by
ssh. I found it don't work correctly with large file, maybe this is
the reason.
···
On 9 7 , 1 15 , rio4ruby <Christopher.Kleck...@gmail.com> wrote:
On Sep 6, 9:41 pm, optman <opt...@gmail.com> wrote:
> On 9 7 , 1 24 , John Joyce <dangerwillrobinsondan...@gmail.com> > > wrote:
> I have seen a line of code like
> put( File.read(sourceFile),targetFile)
> if File.read() return the entire file content, what if sourceFile is a
> large file?
Then you are in trouble if you use File.read(). From your example I
can don't know what the method #put does, but one might logically
surmise that its function is to put a string (the output of File.read)
into targetFile.
Reading a file into a string and then writing that string to a file is
not a good solution for large files. The module ::FileUtils contains a
method #cp which very efficiently (by ruby standards) copies one file
to another -- without requiring that the entire contents of the source
file be copied into memory first.
Rio (http://rio.rubyforge.org) will also copy a file without requiring
the source file being read into memory first:
On Sep 6, 10:41 pm, optman <opt...@gmail.com> wrote:
On 9 7 , 1 15 , rio4ruby <Christopher.Kleck...@gmail.com> wrote:
> On Sep 6, 9:41 pm, optman <opt...@gmail.com> wrote:
> > On 9 7 , 1 24 , John Joyce <dangerwillrobinsondan...@gmail.com> > > > wrote:
> > I have seen a line of code like
> > put( File.read(sourceFile),targetFile)
> > if File.read() return the entire file content, what if sourceFile is a
> > large file?
> Then you are in trouble if you use File.read(). From your example I
> can don't know what the method #put does, but one might logically
> surmise that its function is to put a string (the output of File.read)
> into targetFile.
> Reading a file into a string and then writing that string to a file is
> not a good solution for large files. The module ::FileUtils contains a
> method #cp which very efficiently (by ruby standards) copies one file
> to another -- without requiring that the entire contents of the source
> file be copied into memory first.
> Rio (http://rio.rubyforge.org) will also copy a file without requiring
> the source file being read into memory first:
> rio('sourceFile') > rio('targetFile')
Method #put is from Capistrano, which upload file to remote server by
ssh. I found it don't work correctly with large file, maybe this is
the reason.- Hide quoted text -
> > On Sep 6, 9:41 pm, optman <opt...@gmail.com> wrote:
> > > On 9 7 , 1 24 , John Joyce <dangerwillrobinsondan...@gmail.com> > > > > wrote:
> > > I have seen a line of code like
> > > put( File.read(sourceFile),targetFile)
> > > if File.read() return the entire file content, what if sourceFile is a
> > > large file?
> > Then you are in trouble if you use File.read(). From your example I
> > can don't know what the method #put does, but one might logically
> > surmise that its function is to put a string (the output of File.read)
> > into targetFile.
> > Reading a file into a string and then writing that string to a file is
> > not a good solution for large files. The module ::FileUtils contains a
> > method #cp which very efficiently (by ruby standards) copies one file
> > to another -- without requiring that the entire contents of the source
> > file be copied into memory first.
> > Rio (http://rio.rubyforge.org) will also copy a file without requiring
> > the source file being read into memory first:
> > rio('sourceFile') > rio('targetFile')
> Method #put is from Capistrano, which upload file to remote server by
> ssh. I found it don't work correctly with large file, maybe this is
> the reason.- Hide quoted text -