method

basename

v1_9_2_180 - Show latest stable - Class: File
basename(p1, p2 = v2)
public

Returns the last component of the filename given in file_name, which must be formed using forward slashes (“/”) regardless of the separator used on the local file system. If suffix is given and present at the end of file_name, it is removed.

File.basename("/home/gumby/work/ruby.rb")          #=> "ruby.rb"
File.basename("/home/gumby/work/ruby.rb", ".rb")   #=> "ruby"

1Note

For the file path use File.dirname

metavida · Jan 27, 20103 thanks

File.dirname provides what File.basename omits.