Today I Learned
Needing to reduce a pathname into the filename without it’s extension is something I need to do often. But not too often. Just often enough to forget how I last did it, and clobber together a solution anew.
So this time I’m writing down the briefest solution I’ve found in Ruby, in hopes that it’ll commit to my memory.
require "pathname" pathname = Pathname.new("~/some/path/to/the/mountains.jpg") pathname.basename(pathname.extname).to_s # => "mountains"
Pathname is a great tool in the standard library.