ClearMyBench
Welcome, Guest
Please Login or Register.    Lost Password?
Re:Ruby basics (1 viewing) (1) Guest
Go to bottom Post Reply Favoured: 0
TOPIC: Re:Ruby basics
#4511
ShriNi (User)
Software Techie (PEGA) currently on a Career Break
Platinum Boarder
Posts: 4000
graph
User Offline Click here to see the profile of this user
Gender: Female Location: Secundrabad India Birthdate: 1983-09-29
Re:Ruby basics 3 Years, 11 Months ago Karma: 0  
The File.open Method

We can use File.open method to create a new file object and assign that file object to a file.

However, there is one difference in between File.open and File.new methods.


The difference is that the File.open method can be associated with a block, whereas you cannot do the same using the File.new method.
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#4512
ShriNi (User)
Software Techie (PEGA) currently on a Career Break
Platinum Boarder
Posts: 4000
graph
User Offline Click here to see the profile of this user
Gender: Female Location: Secundrabad India Birthdate: 1983-09-29
Re:Ruby basics 3 Years, 11 Months ago Karma: 0  
Here is a list of the Different Modes of Opening a File:

Modes Description

r Read-only mode. The file pointer is placed at the beginning of the file. This is the default mode.

r+ Read-write mode. The file pointer will be at the beginning of the file
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#4513
ShriNi (User)
Software Techie (PEGA) currently on a Career Break
Platinum Boarder
Posts: 4000
graph
User Offline Click here to see the profile of this user
Gender: Female Location: Secundrabad India Birthdate: 1983-09-29
Re:Ruby basics 3 Years, 11 Months ago Karma: 0  
w mode

Write-only mode. Overwrites the file if the file exists. If the file does not exist, creates a new file for writing.


w+ mode


Read-write mode. Overwrites the existing file if the file exists. If the file does not exist, creates a new file for reading and writing
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#4514
ShriNi (User)
Software Techie (PEGA) currently on a Career Break
Platinum Boarder
Posts: 4000
graph
User Offline Click here to see the profile of this user
Gender: Female Location: Secundrabad India Birthdate: 1983-09-29
Re:Ruby basics 3 Years, 11 Months ago Karma: 0  
mode a


Write-only mode. The file pointer is at the end of the file if the file exists. That is, the file is in the append mode. If the file does not exist, it creates a new file for writing.
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#4515
ShriNi (User)
Software Techie (PEGA) currently on a Career Break
Platinum Boarder
Posts: 4000
graph
User Offline Click here to see the profile of this user
Gender: Female Location: Secundrabad India Birthdate: 1983-09-29
Re:Ruby basics 3 Years, 11 Months ago Karma: 0  
mode a+

Read and write mode. The file pointer is at the end of the file if the file exists.

The file opens in the append mode. If the file does not exist, it creates a new file for reading and writing.
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#4516
ShriNi (User)
Software Techie (PEGA) currently on a Career Break
Platinum Boarder
Posts: 4000
graph
User Offline Click here to see the profile of this user
Gender: Female Location: Secundrabad India Birthdate: 1983-09-29
Re:Ruby basics 3 Years, 11 Months ago Karma: 0  
Reading and Writing Files:


The same methods that we've been using for 'simple' I/O are available for all file objects

. So, gets reads a line from standard input, and aFile.gets reads a line from the file object aFile
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
Go to top Post Reply
get the latest posts directly to your desktop
logo footer   Copyright 2009 - 2013 HotRecruiter.Com - All Rights Reserved