Forum: Ruby what's wrong with these?

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.
E4b50a75fa3c4dc245fd60f2bbf94ff4?d=identicon&s=25 Kinroc Cornik (cornik)
on 2009-04-06 03:40
Version: ruby 1.9.1p0 (2009-01-30 revision 21907) [i686-linux]
Is there something wrong with this version?

1:
Dir.foreach("/tmp") {|f| puts f if File.directory?(f) }
-- it just prints '.' and '..'

2:
puts Dir.tmpdir
Dir.mktmpdir { |i|  puts i }
-- it says 'undefined method'
770048af205ed307b8cf35ae2282ee2f?d=identicon&s=25 Michael Malone (Guest)
on 2009-04-06 04:04
(Received via mailing list)
Humphrey Alba wrote:
> Version: ruby 1.9.1p0 (2009-01-30 revision 21907) [i686-linux]
> Is there something wrong with this version?
>
> 1:
> Dir.foreach("/tmp") {|f| puts f if File.directory?(f) }
> -- it just prints '.' and '..'
>

Have you checked to see if you do have directories inside /tmp other
than '.' and '..'?
> 2:
> puts Dir.tmpdir
> Dir.mktmpdir { |i|  puts i }
> -- it says 'undefined
As for "undefined method" you're quite right, I can't find Dir#tmpdir
defined anywhere either, and yet it's in the docs...what's the deal
guys?

=======================================================================
This email, including any attachments, is only for the intended
addressee.  It is subject to copyright, is confidential and may be
the subject of legal or other privilege, none of which is waived or
lost by reason of this transmission.
If the receiver is not the intended addressee, please accept our
apologies, notify us by return, delete all copies and perform no
other act on the email.
Unfortunately, we cannot warrant that the email has not been
 altered or corrupted during transmission.
=======================================================================
F1d6cc2b735bfd82c8773172da2aeab9?d=identicon&s=25 Nobuyoshi Nakada (nobu)
on 2009-04-06 04:20
(Received via mailing list)
Hi,

At Mon, 6 Apr 2009 11:03:09 +0900,
Michael Malone wrote in [ruby-talk:333071]:
> > 2:
> > puts Dir.tmpdir
> > Dir.mktmpdir { |i|  puts i }
> > -- it says 'undefined
> As for "undefined method" you're quite right, I can't find Dir#tmpdir
> defined anywhere either, and yet it's in the docs...what's the deal guys?

require 'tmpdir'
E4b50a75fa3c4dc245fd60f2bbf94ff4?d=identicon&s=25 Kinroc Cornik (cornik)
on 2009-04-06 06:11
Michael Malone wrote:
> Humphrey Alba wrote:
>> Version: ruby 1.9.1p0 (2009-01-30 revision 21907) [i686-linux]
>> Is there something wrong with this version?
>>
>> 1:
>> Dir.foreach("/tmp") {|f| puts f if File.directory?(f) }
>> -- it just prints '.' and '..'
>>
>
> Have you checked to see if you do have directories inside /tmp other
> than '.' and '..'?

Yes, there are directories inside /tmp
E4b50a75fa3c4dc245fd60f2bbf94ff4?d=identicon&s=25 Kinroc Cornik (cornik)
on 2009-04-06 06:12
Nobuyoshi Nakada wrote:
> Hi,
>
> At Mon, 6 Apr 2009 11:03:09 +0900,
> Michael Malone wrote in [ruby-talk:333071]:
>> > 2:
>> > puts Dir.tmpdir
>> > Dir.mktmpdir { |i|  puts i }
>> > -- it says 'undefined
>> As for "undefined method" you're quite right, I can't find Dir#tmpdir
>> defined anywhere either, and yet it's in the docs...what's the deal guys?
>
> require 'tmpdir'

Thanks.
7a561ec0875fcbbe3066ea8fe288ec77?d=identicon&s=25 Sebastian Hungerecker (Guest)
on 2009-04-06 07:25
(Received via mailing list)
Humphrey Alba wrote:
> Dir.foreach("/tmp") {|f| puts f if File.directory?(f) }
> -- it just prints '.' and '..'

Dir.foreach("/tmp") {|f| puts f if File.directory?("/tmp/#{f}") }
or
Dir.chdir("/tmp") do
  Dir.foreach(".") {|f| puts f if File.directory?(f) }
end
or
Dir.glob("/tmp/*") {|f| puts f if File.directory?(f) }
or
Dir.glob("/tmp/*/") {|f| puts f}
or
puts Dir.glob("/tmp/*/")
or
puts Dir["/tmp/*/"]

The glob-ones will not include hidden directories or . and .. and they
will
print the full-path to the dir (though you could also use chdir with
glob, if
you don't want the full path).

HTH,
Sebastian
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (Guest)
on 2009-04-06 10:18
(Received via mailing list)
On 06.04.2009 03:39, Humphrey Alba wrote:
> Version: ruby 1.9.1p0 (2009-01-30 revision 21907) [i686-linux]
> Is there something wrong with this version?
>
> 1:
> Dir.foreach("/tmp") {|f| puts f if File.directory?(f) }
> -- it just prints '.' and '..'

This is because of what Dir.foreach returns:

http://www.ruby-doc.org/core/classes/Dir.html#M002327

Hint: paths are missing.

> 2:
> puts Dir.tmpdir
> Dir.mktmpdir { |i|  puts i }
> -- it says 'undefined method'

Well, what do you conclude from that?

Kind regards

  robert
851acbab08553d1f7aa3eecad17f6aa9?d=identicon&s=25 Ken Bloom (Guest)
on 2009-04-06 15:55
(Received via mailing list)
On Sun, 05 Apr 2009 21:19:04 -0500, Nobuyoshi Nakada wrote:

>> guys?
>
> require 'tmpdir'

Yeah. The core rdoc on http://www.ruby-doc.org/ has a pitfall that it
includes the standard libraries as well. (Nobody separated out the
standard libraries from that.)

If you want to know what's in the core, getting a copy of PickAxe is a
better bet.

--Ken
This topic is locked and can not be replied to.