How to open a file in Ruby?
Answer / Janpriya Gaur
To open a file in Ruby, you can use the File.open method. For example: File.open('filename.txt', 'r') { |file| file.each_line do |line| puts line end } This opens the file with read-only access and iterates through each line printing it.
| Is This Answer Correct ? | 0 Yes | 0 No |
Is ruby whitespace-dependent?
Are ruby strings are mutable?
Explain me what is the difference between symbol and string?
Tell us how would you implement hash in ruby internally?
Explain about operators in Ruby?
What are the looping structures available in ruby?
What are advantages of using ruby?
Explain about Float, Dig and Max?
what is a class library in Ruby?
Explain when self.up and self.down method is used?
What are blocks and procs?
Explain about garbage collection feature of ruby?