Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Pathname['abc'] instead of Pathname('abc') global method as constructor alternative #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
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 ext/pathname/lib/pathname.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ def prepend_prefix(prefix, relpath)
end
private :prepend_prefix

# See <tt>Dir.glob</tt>. Returns or yields Pathname objects.
def glob(*args)
self.class.glob(self + args.shift, *args)
end

# Returns clean pathname of +self+ with consecutive slashes and useless dots
# removed. The filesystem is not accessed.
#
Expand Down
11 changes: 11 additions & 0 deletions ext/pathname/pathname.c
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,15 @@ path_s_getwd(VALUE klass)
return rb_class_new_instance(1, &str, klass);
}

/*
* Returns a new instance of Pathname initialized with string
*/
static VALUE
path_s_square_brackets(VALUE self, VALUE string)
{
return rb_class_new_instance(1, &string, rb_cPathname);
}

/*
* Return the entries (files and subdirectories) in the directory, each as a
* Pathname object.
Expand Down Expand Up @@ -969,6 +978,7 @@ path_unlink(VALUE self)
static VALUE
path_f_pathname(VALUE self, VALUE str)
{
rb_warn("Kernel#Pathname is deprecated; use Pathname.[] instead");
return rb_class_new_instance(1, &str, rb_cPathname);
}

Expand Down Expand Up @@ -1225,6 +1235,7 @@ Init_pathname()
rb_define_method(rb_cPathname, "world_writable?", path_world_writable_p, 0);
rb_define_method(rb_cPathname, "writable_real?", path_writable_real_p, 0);
rb_define_method(rb_cPathname, "zero?", path_zero_p, 0);
rb_define_singleton_method(rb_cPathname, "[]", path_s_square_brackets, 1);
rb_define_singleton_method(rb_cPathname, "glob", path_s_glob, -1);
rb_define_singleton_method(rb_cPathname, "getwd", path_s_getwd, 0);
rb_define_singleton_method(rb_cPathname, "pwd", path_s_getwd, 0);
Expand Down