Ruby: I/O Flashcards
1
Q
How do you create a new file?
A
Ruby has a built in class called File. So it follows the same rules as creating an instance of a class. For example:
(instance of a class) class Person end
person = Person.new(“James”)
Example for file:
file = File.new(“filename”, “r”)
r* is example
2
Q
mode strings: read
A
r
3
Q
mode string: write
A
w
4
Q
mode string: read and write
A
r+