• +91 9723535972
  • info@interviewmaterial.com

Ruby Interview Questions and Answers

Question - How to open a file in Ruby?

Answer -

A Ruby file can be created using different methods for reading, writing or both.

There are two methods to open a file in Ruby.

File.new method : Using this method a new file can be created for reading, writing or both.
File.open method : Using this method a new file object is created. That file object is assigned to a file.
Difference between both the methods is that File.open method can be associated with a block while File.new method can't.

Syntax:

f = File.new("fileName.rb")  
Or,

File.open("fileName.rb", "mode") do |f|  

Comment(S)

Show all Coment

Leave a Comment




NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners