pathname icon indicating copy to clipboard operation
pathname copied to clipboard

Please consider adding Pathname.home

Open josb opened this issue 1 year ago • 4 comments

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).

josb avatar Apr 11 '24 21:04 josb

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

hsbt avatar Apr 16 '24 05:04 hsbt

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

josb avatar Apr 16 '24 05:04 josb

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>

knu avatar Apr 16 '24 14:04 knu