Forum: Ruby Pathname

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
45196398e9685000d195ec626d477f0e?d=identicon&s=25 unknown (Guest)
on 2006-05-28 04:58
(Received via mailing list)
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.
0ec4920185b657a03edf01fff96b4e9b?d=identicon&s=25 Yukihiro Matsumoto (Guest)
on 2006-05-28 15:41
(Received via mailing list)
Hi,

akr-san is responsible for pathname library.

							matz.

In message "Re: Pathname"
    on Sun, 28 May 2006 11:56:05 +0900, transfire@gmail.com 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.
817f4e5953cadb1deb429e410c823c92?d=identicon&s=25 Tanaka Akira (Guest)
on 2006-05-30 04:02
(Received via mailing list)
In article <1148784962.397850.112760@y43g2000cwc.googlegroups.com>,
  transfire@gmail.com 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.
45196398e9685000d195ec626d477f0e?d=identicon&s=25 unknown (Guest)
on 2006-05-30 06:25
(Received via mailing list)
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.
Aee77dba395ece0a04c688b05b07cd63?d=identicon&s=25 Daniel Berger (Guest)
on 2006-05-30 06:41
(Received via mailing list)
transfire@gmail.com 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
Aee77dba395ece0a04c688b05b07cd63?d=identicon&s=25 Daniel Berger (Guest)
on 2006-05-30 06:57
(Received via mailing list)
Daniel Berger wrote:
> transfire@gmail.com wrote:

<snip>

>> 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: http://www.rcrchive.net/rcr/show/279

Regards,

Dan
E34b5cae57e0dd170114dba444e37852?d=identicon&s=25 Logan Capaldo (Guest)
on 2006-05-30 18:18
(Received via mailing list)
On May 30, 2006, at 12:55 AM, Daniel Berger 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: 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.
45196398e9685000d195ec626d477f0e?d=identicon&s=25 unknown (Guest)
on 2006-05-30 20:09
(Received via mailing list)
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.
F1d6cc2b735bfd82c8773172da2aeab9?d=identicon&s=25 Nobuyoshi Nakada (Guest)
on 2006-05-31 05:08
(Received via mailing list)
2006/5/31, transfire@gmail.com <transfire@gmail.com>:
>   $P = lambda { |s| Pathname.new(s) }
>
>   $P['a/b']

class << Pathname
  alias [] new
end

Pathname['a/b']

P = Pathname
P['a/b']
This topic is locked and can not be replied to.