ruby / pathname

Pathname represents the name of a file or directory on the filesystem, but not the file itself.
BSD 2-Clause "Simplified" License
26 stars 16 forks source link

Please consider adding Pathname.home #37

Open josb opened 5 months ago

josb commented 5 months ago

Please consider adding Pathname.home for symmetry with Dir.home but returning a Pathname instead of a String, and to avoid having to use Pathname.new(Dir.home).

hsbt commented 4 months ago

I don't understand why you don't use Pathname.new(Dir.home). What's the problem that?

josb commented 4 months ago

It works, but is more verbose and I expected Pathname.home to work in the first place (POLA).

knu commented 4 months ago

It'd be cool to have it aliased to ~.

class Pathname
  class << self
    def home(user_name = nil)
      Pathname(Dir.home(user_name))
    end

    alias ~ home
  end
end

p Pathname.~         #=> #<Pathname:/Users/knu>
p Pathname.~('root') #=> #<Pathname:/var/root>