# Pathname

**URL:** <https://www.ruby-forum.com/t/pathname/95317>\
**Category:** Ruby\
**Created:** [May 28, 2006, 4:58am UTC](https://www.ruby-forum.com/t/pathname/95317 "2006-05-28T04:58:01Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [May 28, 2006, 4:58am UTC](https://www.ruby-forum.com/t/pathname/95317/1 "2006-05-28T04:58:01Z")

</div>

About 6 months ago or so, I rewrote the Pathname library to internally  
store a path as an Array instead of a String. It appears to be about  
20% faster than the original and the code is a good bit less complex. I  
no longer subscribte to ruby-dev and I’m not sure who is responsible  
for such things, so I’m posting here. Would a Ruby developer like to  
have a look and consider it as an update of the current lib?

Thanks,  
T.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [May 28, 2006, 3:41pm UTC](https://www.ruby-forum.com/t/pathname/95317/2 "2006-05-28T15:41:36Z")

</div>

Hi,

akr-san is responsible for pathname library.

```
						matz.

```

In message “Re: Pathname”  
on Sun, 28 May 2006 11:56:05 +0900, removed\_email\_address@domain.invalid writes:  
|  
|About 6 months ago or so, I rewrote the Pathname library to internally  
|store a path as an Array instead of a String. It appears to be about  
|20% faster than the original and the code is a good bit less complex. I  
|no longer subscribte to ruby-dev and I’m not sure who is responsible  
|for such things, so I’m posting here. Would a Ruby developer like to  
|have a look and consider it as an update of the current lib?  
|  
|Thanks,  
|T.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [May 30, 2006, 4:02am UTC](https://www.ruby-forum.com/t/pathname/95317/3 "2006-05-30T04:02:20Z")

</div>

In article [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid),  
removed\_email\_address@domain.invalid writes:

> About 6 months ago or so, I rewrote the Pathname library to internally  
> store a path as an Array instead of a String. It appears to be about  
> 20% faster than the original and the code is a good bit less complex. I  
> no longer subscribte to ruby-dev and I’m not sure who is responsible  
> for such things, so I’m posting here. Would a Ruby developer like to  
> have a look and consider it as an update of the current lib?

I don’t like it. A pathname may have different structure on  
different environment.

I think rewriting it in C is appropriate way to make it faster.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [May 30, 2006, 6:25am UTC](https://www.ruby-forum.com/t/pathname/95317/4 "2006-05-30T06:25:59Z")

</div>

Tanaka wrote:

> I think rewriting it in C is appropriate way to make it faster.

I won’t disagree with you there. So if that’s in the works than no  
worries.

Two thoughts though. I liked being about to use \<\< to add to a path.  
Eg.

pn = Pathname.new(‘a/b’)  
pn \<\< ‘c’  
pn #=\> #Pathname:a/b/c

Some other array-like methods seem useful too, #each for instance.

More importantly, I think it would be nice if there were a shorter way  
to define a path, perhaps a percent literal like %p{a/b}. Haing to  
spell out Pathname.new all the time deters one from using it over a  
simple String and the File class methods.

Thanks for responding Tanaka,  
T.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [May 30, 2006, 6:57am UTC](https://www.ruby-forum.com/t/pathname/95317/5 "2006-05-30T06:57:01Z")

</div>

Daniel B. wrote:

> removed\_email\_address@domain.invalid wrote:

> > More importantly, I think it would be nice if there were a shorter way  
> > to define a path, perhaps a percent literal like %p{a/b}.
> 
> Good idea. I’m stealing it for pathname2. 🙂

Well, I would have stolen it, except that I forgot that there’s no way  
to define % literals in Ruby 1.8 afaik. I’m not sure about 1.9.

Related RCR: [RCR 279: User defined % literals](http://www.rcrchive.net/rcr/show/279)

Regards,

Dan

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [May 30, 2006, 6:18pm UTC](https://www.ruby-forum.com/t/pathname/95317/6 "2006-05-30T18:18:34Z")

</div>

On May 30, 2006, at 12:55 AM, Daniel B. wrote:

> Well, I would have stolen it, except that I forgot that there’s no  
> way to define % literals in Ruby 1.8 afaik. I’m not sure about 1.9.
> 
> Related RCR: [RCR 279: User defined % literals](http://www.rcrchive.net/rcr/show/279)
> 
> Regards,
> 
> Dan

Well, is this close enough?

module Kernel  
def pn(s)  
Pathname.new(s)  
end  
end

pn %{a/b}

It almost looks like a % literal.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [May 30, 2006, 6:41am UTC](https://www.ruby-forum.com/t/pathname/95317/7 "2006-05-30T06:41:38Z")

</div>

removed\_email\_address@domain.invalid wrote:

> pn \<\< ‘c’  
> pn #=\> #Pathname:a/b/c
> 
> Some other array-like methods seem useful too, #each for instance.

The pathname2 package already does this (although you use ‘+’ instead of  
‘\<\<’).

> More importantly, I think it would be nice if there were a shorter way  
> to define a path, perhaps a percent literal like %p{a/b}.

Good idea. I’m stealing it for pathname2. 🙂

Regards,

Dan

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [May 30, 2006, 8:09pm UTC](https://www.ruby-forum.com/t/pathname/95317/8 "2006-05-30T20:09:54Z")

</div>

Although you just end up doing this

pn(‘a/b’)

when it’s within other calls anyway. Plus it’s yet another pass through  
kernel method. Maybe this would be better:

$P = lambda { |s| Pathname.new(s) }

$P[‘a/b’]

Just a thought.  
T.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [May 31, 2006, 5:08am UTC](https://www.ruby-forum.com/t/pathname/95317/9 "2006-05-31T05:08:05Z")

</div>

2006/5/31, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> $P = lambda { |s| Pathname.new(s) }
> 
> $P[‘a/b’]

class \<\< Pathname  
alias [] new  
end

Pathname[‘a/b’]

P = Pathname  
P[‘a/b’]
