DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Extracting Filename (without Extension) In Ruby

08.23.2009
| 18337 views |
  • submit to reddit
        
Shortest, rock-solid idiom for removing the extension, without
removing the preceding path:

  fname.chomp(File.extname(fname))

Best idiom if you are removing the path also:

  File.basename(fname, '.*')