Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Dir#seek

seek(position) → self

Sets the position in self and returns self. The value of position should have been returned from an earlier call to tell; if not, the return values from subsequent calls to read are unspecified.

See Dir As Stream-Like.

Examples:

Example
dir = Dir.new('example')
dir.pos      # => 0
dir.seek(3)  # => #<Dir:example>
dir.pos      # => 3
dir.seek(30) # => #<Dir:example>
dir.pos      # => 5
See also #rewind #tell #read #to_path also in 4.1 · 4.0 · 3.4 · 3.2 · 3.1 · 3.0