in Hacking

Ruby undocument File.basename trick

Just stumbled upon the following trick to get the basename without an extension in Ruby:
(I didn’t know you could use “.*” to remove any extension).

File.basename( "filename/sample-filename.html", ".*" )
=> "sample-filename"
Share
  • Related Content by Tag