Skip to content

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

class method

File.split

(::path file_name) -> [ ::String, ::String ]
File.split(string) → array_of_strings

Returns a 2-element array of strings containing the ::dirname and ::basename of the the given string:

Example
File.split('doc/maintainers.md') # => ["doc", "maintainers.md"]
File.split('doc/')               # => [".", "doc"]
File.split('README.md')          # => [".", "README.md"]
File.split('/tmp/nosuch')        # => ["/tmp", "nosuch"]
File.split('@@##$$/%%^^&&')      # => ["@@#\#$$", "%%^^&&"]
See also .socket? .stat .size? .sticky? also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0