Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

Pathname#sysopen

(?::String mode, ?::Integer perm) -> ::Integer
sysopen(mode = 'r', permissions = 0666) → integer

Opens the file at the path in self with the given mode and permissions; returns the integer file descriptor.

If the file is to be readable, it must exist; if the file is to be writable and does not exist, it is created with the given permissions:

Example
pn = Pathname('doc/t.tmp')
pn.write('foo')
fd = pn.sysopen             # => 5
IO.new(fd).close
fd = pn.sysopen('w')        # => 5
IO.new(fd).close
fd = pn.sysopen('r', 0o644) # => 5
IO.new(fd).close
pn.delete
See also #symlink? #to_path #sub_ext #to_s also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0