From 391fc2eeecfc2f0d0f851b0c27ba02e041fe2cd9 Mon Sep 17 00:00:00 2001 From: akr Date: Mon, 5 May 2014 12:49:27 +0000 Subject: [PATCH] * ext/pathname/lib/pathname.rb (Pathname#/): Aliased to Pathname#+. Suggested by Alexey Muranov. [ruby-core:61432] [Feature #9625] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45826 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ NEWS | 3 +++ ext/pathname/lib/pathname.rb | 5 +++++ test/pathname/test_pathname.rb | 4 ++++ 4 files changed, 17 insertions(+) diff --git a/ChangeLog b/ChangeLog index 9605862834..8a6828634c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Mon May 5 21:48:04 2014 Tanaka Akira + + * ext/pathname/lib/pathname.rb (Pathname#/): Aliased to Pathname#+. + Suggested by Alexey Muranov. [ruby-core:61432] [Feature #9625] + Mon May 5 17:26:09 2014 Tadayoshi Funaba * math.c (rb_math_sqrt): omitted exporting an unused function, diff --git a/NEWS b/NEWS index 379d5870a5..681f0eea75 100644 --- a/NEWS +++ b/NEWS @@ -70,6 +70,9 @@ with all sufficient information, see the ChangeLog file. * Extended methods: * find method accepts "ignore_error" keyword argument. +* Pathname + * Pathname#/ is aliased to Pathname#+. + === Stdlib compatibility issues (excluding feature bug fixes) * time.rb diff --git a/ext/pathname/lib/pathname.rb b/ext/pathname/lib/pathname.rb index aa9464799d..380e740399 100644 --- a/ext/pathname/lib/pathname.rb +++ b/ext/pathname/lib/pathname.rb @@ -324,12 +324,17 @@ class Pathname # p2 = p1 + "bin/ruby" # Pathname:/usr/bin/ruby # p3 = p1 + "/etc/passwd" # Pathname:/etc/passwd # + # # / is aliased to +. + # p4 = p1 / "bin/ruby" # Pathname:/usr/bin/ruby + # p5 = p1 / "/etc/passwd" # Pathname:/etc/passwd + # # This method doesn't access the file system; it is pure string manipulation. # def +(other) other = Pathname.new(other) unless Pathname === other Pathname.new(plus(@path, other.to_s)) end + alias / + def plus(path1, path2) # -> path # :nodoc: prefix2 = path2 diff --git a/test/pathname/test_pathname.rb b/test/pathname/test_pathname.rb index 4e88db754d..24f6bb942d 100644 --- a/test/pathname/test_pathname.rb +++ b/test/pathname/test_pathname.rb @@ -213,6 +213,10 @@ class TestPathname < Test::Unit::TestCase defassert(:plus, 'a//b/d//e', 'a//b/c', '../d//e') + def test_slash + assert_kind_of(Pathname, Pathname("a") / Pathname("b")) + end + def test_parent assert_equal(Pathname("."), Pathname("a").parent) end