diff --git a/lib/pathname_builtin.rb b/lib/pathname_builtin.rb index 1dedf5e..7b33a03 100644 --- a/lib/pathname_builtin.rb +++ b/lib/pathname_builtin.rb @@ -165,6 +165,7 @@ # These methods are a facade for Dir: # - Pathname.glob(*args) # - Pathname.getwd / Pathname.pwd +# - Pathname.home # - #rmdir # - #entries # - #each_entry(&block) @@ -1126,6 +1127,10 @@ class << self alias pwd getwd end + # See Dir.home. Returns the home directory of the current user, or + # the named user if given, as a Pathname. + def Pathname.home(user_name = nil) self.new(Dir.home(user_name)) end + # Return the entries (files and subdirectories) in the directory, each as a # Pathname object. def entries() Dir.entries(@path).map {|f| self.class.new(f) } end diff --git a/test/pathname/test_pathname.rb b/test/pathname/test_pathname.rb index e2d6a09..8922f9d 100644 --- a/test/pathname/test_pathname.rb +++ b/test/pathname/test_pathname.rb @@ -1364,6 +1364,15 @@ def test_s_pwd assert_kind_of(Pathname, wd) end + def test_s_home + home = Pathname.home + assert_kind_of(Pathname, home) + assert_equal(Dir.home, home.to_path) + user_home = Pathname.home(ENV['USER']) + assert_kind_of(Pathname, user_home) + assert_equal(Dir.home(ENV['USER']), user_home.to_path) + end + def test_glob with_tmpchdir('rubytest-pathname') {|dir| Dir.mkdir("d")