-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfile-open.rb
More file actions
20 lines (16 loc) 路 747 Bytes
/
Copy pathfile-open.rb
File metadata and controls
20 lines (16 loc) 路 747 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Create a file
file = File.new('create.txt', 'w+')
# Write to a file
file.puts('some text')
file.puts('second line')
file.write('some other stuff without new line')
file.write('on the same line')
# Operations
file.close
# File modes
# r: read-only, starts at beginning of file (default mode).
# r+: read-write, starts at beginning of file.
# w: write-only, truncates existing file to zero length or creates a new file for writing.
# w+: read-write, truncates existing file to zero length or creates a new file for reading and writing.
# a: write-only, starts at end of file if file exists, otherwise creates a new file for writing.
# a+: read-write, starts at end of file if file exists, otherwise creates a new file for reading and writing.