Skip to content

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

instance method

IO#advise

(:normal | :sequential | :random | :willneed | :dontneed | :noreuse advise, ?::Integer offset, ?::Integer len) -> nil
advise(advice, offset = 0, len = 0) → nil

Invokes Posix system call posix_fadvise(2), which announces an intention to access data from the current file in a particular manner.

The arguments and results are platform-dependent.

The relevant data is specified by:

  • offset: The offset of the first byte of data.

  • len: The number of bytes to be accessed; if len is zero, or is larger than the number of bytes remaining, all remaining bytes will be accessed.

Argument advice is one of the following symbols:

  • :normal: The application has no advice to give about its access pattern for the specified data. If no advice is given for an open file, this is the default assumption.

  • :sequential: The application expects to access the specified data sequentially (with lower offsets read before higher ones).

  • :random: The specified data will be accessed in random order.

  • :noreuse: The specified data will be accessed only once.

  • :willneed: The specified data will be accessed in the near future.

  • :dontneed: The specified data will not be accessed in the near future.

Not implemented on all platforms.

See also #<< #autoclose= .write #autoclose? also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0