---
date: "2020-01-13"
---

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.

```ruby
require "pathname"
pathname = Pathname.new("~/some/path/to/the/mountains.jpg")
pathname.basename(pathname.extname).to_s # => "mountains"
```

[Pathname](https://ruby-doc.org/stdlib-2.7.0/libdoc/pathname/rdoc/Pathname.html) is a great tool in the standard library.
