From: ara.t.howard@... Date: 2006-08-09T23:27:27+09:00 Subject: Re: [PATCH] Pathname.to_a --Boundary-00=_TSd2EyMm63MlBlr Content-Type: MULTIPART/Mixed; BOUNDARY="Boundary-00=_TSd2EyMm63MlBlr" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --Boundary-00=_TSd2EyMm63MlBlr Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed fyi fortytwo :~/tmp > irb -r pathname irb(main):001:0> pn = Pathname.new(File.expand_path('.')) => # irb(main):002:0> pn.dirname.basename => # cheers. -a -- to foster inner awareness, introspection, and reasoning is more efficient than meditation and prayer. - h.h. the 14th dali lama --Boundary-00=_TSd2EyMm63MlBlr Content-Type: MULTIPART/MIXED; BOUNDARY="Boundary-00=_TSd2EyMm63MlBlr" Content-ID: Content-Description: This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --Boundary-00=_TSd2EyMm63MlBlr Content-Type: TEXT/PLAIN; CHARSET=US-ASCII Content-ID: --Boundary-00=_TSd2EyMm63MlBlr-- --Boundary-00=_TSd2EyMm63MlBlr Content-Type: TEXT/PLAIN; CHARSET=utf-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Content-ID: Content-Description: Content-Disposition: INLINE Hi folks, today I found myself wanting to get the parent directory name of a file, = so I=20 was looking whether Pathname has an to_a so I could do: parent_dir =3D path.to_a[-2] Since it didn't exist, I've written a small patch against CVS to add this= =20 simple function, maybe you find it useful :-) C'ya, Marc --=20 Marc Haisenko Comdasys AG R=C3=BCdesheimer Stra=C3=9Fe 7 D-80686 M=C3=BCnchen Tel: =C2=A0 +49 (0)89 - 548 43 33 21 Fax: =C2=A0 +49 (0)89 - 548 43 33 29 e-mail: haisenko@comdasys.com http://www.comdasys.com --Boundary-00=_TSd2EyMm63MlBlr Content-Type: TEXT/X-DIFF; CHARSET=utf-8; NAME=pathname-to_a.patch Content-ID: Content-Description: Content-Disposition: ATTACHMENT; FILENAME=pathname-to_a.patch --- pathname.rb.orig 2006-07-08 10:56:27.000000000 +0200 +++ pathname.rb 2006-08-09 14:10:54.000000000 +0200 @@ -242,6 +242,13 @@ @path.dup end + # Return the path as an Array. + def to_a + a = @path.split SEPARATOR_PAT + a.shift if a[0].size == 0 + a + end + # to_path is implemented so Pathname objects are usable with File.open, etc. alias_method TO_PATH, :to_s --Boundary-00=_TSd2EyMm63MlBlr-- --Boundary-00=_TSd2EyMm63MlBlr--