Skip to content

End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

class method

File.open

File.open(path, mode = 'r', perm = 0666, **opts) → file
File.open(path, mode = 'r', perm = 0666, **opts) {|f| ... } → object

Creates a new File object, via File.new with the given arguments.

With no block given, returns the File object.

With a block given, calls the block with the File object and returns the block’s value.

See also .new .owned? .mtime .path also in 4.1 · 4.0 · 3.4 · 3.3 · 3.1 · 3.0