Forum: Ruby unexpected behaviour in 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.
31af45939fec7e3c4ed8a798c0bd9b1a?d=identicon&s=25 M.B.Smillie (Guest)
on 2005-11-15 14:30
(Received via mailing list)
I'm writing a quick script to selectively process some files, and I
found a bit of odd behaviour using Pathname#each and #each_entry,
which is best illustrated, rather than explained:

irb(main):001:0> require 'pathname'
=> true
irb(main):002:0> p = Pathname.new("/home/matt/test")
=> #<Pathname:/home/matt/test>
irb(main):003:0> p.entries.each{ |q|
irb(main):004:1*   puts "operating on: #{q.dirname}/#{q.basename}"
irb(main):005:1> }
operating on: ./.
operating on: ./..
operating on: ./a
operating on: ./b
operating on: ./c

Now, the problem that results is that in the block, I can't do q.read
reliably (or indeed q.anything), because it's looking for q relative
to the current directory, when surely it should be looking relative
to p.

Apart from files not being found if you're not in the correct
directory, this could lead to more difficult-to-detect problems if
you have a structure like the following and run the script in a
directory which has identically-named files to the intended target,
for instance:

/home/matt/project/training/{1, 2, 3, 4, etc}
/home/matt/project/test/{1, 2, 3, 4, etc}

Since even when the directory to be processed is given as an absolute
pathname, its subdirectories are treated as relative pathnames.

I realise that I can solve this by doing (p + q).read inside the
block, but surely this isn't the desired behaviour of Pathname#each?

thanks,
matthew smillie.
31af45939fec7e3c4ed8a798c0bd9b1a?d=identicon&s=25 M.B.Smillie (Guest)
on 2005-11-15 14:33
(Received via mailing list)
> I'm writing a quick script to selectively process some files, and I
> found a bit of odd behaviour using Pathname#each and #each_entry,
> which is best illustrated, rather than explained:

Quick clarification: I do mean Pathname#entries rather than
Pathname#each.

Whoops.
42c83263598da02c136a4ebf8a058182?d=identicon&s=25 akr (Guest)
on 2005-11-15 15:14
(Received via mailing list)
In article <91B61F46-ABB8-48E7-BB2D-97A3DBE87C3C@sms.ed.ac.uk>,
  Matthew Smillie <M.B.Smillie@sms.ed.ac.uk> writes:

> I realise that I can solve this by doing (p + q).read inside the
> block, but surely this isn't the desired behaviour of Pathname#each?

It is intended for consistency to Dir.entries.

Use Pathname#children instead.

Note that Pathname#children doesn't generates "." and "..".
I hope you don't need them.
01872c2150719cb274aef5dd5c48e361?d=identicon&s=25 k-zimir (Guest)
on 2005-11-15 15:17
(Received via mailing list)
hey everybody...

   i need to get off this list. i will have limited access to this
account
for some time and i need tot turn off my lists. i tried "unsubscribe my
name" and send it to the list but it neither unsubscribed me nor showed
up
in the list. on the website i cant really see how to unsubscribe only
how to
subscribe!

\n
5befe95e6648daec3dd5728cd36602d0?d=identicon&s=25 bob.news (Guest)
on 2005-11-15 15:24
(Received via mailing list)
Tanaka Akira wrote:
> Note that Pathname#children doesn't generates "." and "..".
> I hope you don't need them.

Another - possibly simpler - approach would be to use
Dir['/home/matt/test/*'].

Kind regards

    robert
A36e2ad7a1dd10b9709f797344ea5068?d=identicon&s=25 christophe.grandsire (Guest)
on 2005-11-15 15:30
(Received via mailing list)
Selon niels wolf <k-zimir@gmx.net>:

> hey everybody...
>
>    i need to get off this list. i will have limited access to this account
> for some time and i need tot turn off my lists. i tried "unsubscribe my
> name" and send it to the list but it neither unsubscribed me nor showed up
> in the list. on the website i cant really see how to unsubscribe only how to
> subscribe!
>

You need to send the unsubscribe command to
mailto:ruby-talk-ctl@ruby-lang.org,
as indicated in the e-mail you automatically received when you first
joined the
list :) .
--
Christophe Grandsire.

http://rainbow.conlang.free.fr

It takes a straight mind to create a twisted conlang.
0ec4920185b657a03edf01fff96b4e9b?d=identicon&s=25 matz (Guest)
on 2005-11-15 15:30
(Received via mailing list)
Hi,

In message "Re: unsubscribe.. please...."
    on Tue, 15 Nov 2005 23:15:52 +0900, "niels wolf" <k-zimir@gmx.net>
writes:

|   i need to get off this list. i will have limited access to this account
|for some time and i need tot turn off my lists. i tried "unsubscribe my
|name" and send it to the list but it neither unsubscribed me nor showed up
|in the list. on the website i cant really see how to unsubscribe only how to
|subscribe!

You should have sent a command mail to ruby-talk-ctl.  But I will remove
you manually.

							matz.
This topic is locked and can not be replied to.