Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/pathname_builtin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -1126,6 +1127,10 @@ class << self
alias pwd getwd
end

# See <tt>Dir.home</tt>. 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
Expand Down
9 changes: 9 additions & 0 deletions test/pathname/test_pathname.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down