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
file.c
View on GitHub ↗
static VALUE
rb_file_s_split(VALUE klass, VALUE path)
{
FilePathStringValue(path); /* get rid of converting twice */
return rb_assoc_new(rb_file_dirname(path), rb_file_s_basename(1,&path,Qundef));
}
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('@@##$$/%%^^&&') # => ["@@#\#$$", "%%^^&&"]