# What's wrong with these?

**URL:** <https://www.ruby-forum.com/t/whats-wrong-with-these/164794>\
**Category:** Ruby\
**Created:** [April 6, 2009, 3:40am UTC](https://www.ruby-forum.com/t/whats-wrong-with-these/164794 "2009-04-06T03:40:04Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![cornik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/43a26b/32.png) [@cornik](https://www.ruby-forum.com/u/cornik)\
**Post date:** [April 6, 2009, 3:40am UTC](https://www.ruby-forum.com/t/whats-wrong-with-these/164794/1 "2009-04-06T03:40:04Z")

</div>

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’

---

<div class="post-metadata">

**Author:** ![cornik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/43a26b/32.png) [@cornik](https://www.ruby-forum.com/u/cornik)\
**Post date:** [April 6, 2009, 4:04am UTC](https://www.ruby-forum.com/t/whats-wrong-with-these/164794/2 "2009-04-06T04:04:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![cornik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/43a26b/32.png) [@cornik](https://www.ruby-forum.com/u/cornik)\
**Post date:** [April 6, 2009, 6:11am UTC](https://www.ruby-forum.com/t/whats-wrong-with-these/164794/3 "2009-04-06T06:11:55Z")

</div>

Michael M. 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

---

<div class="post-metadata">

**Author:** ![cornik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/43a26b/32.png) [@cornik](https://www.ruby-forum.com/u/cornik)\
**Post date:** [April 6, 2009, 6:12am UTC](https://www.ruby-forum.com/t/whats-wrong-with-these/164794/4 "2009-04-06T06:12:36Z")

</div>

Nobuyoshi N. wrote:

> Hi,
> 
> At Mon, 6 Apr 2009 11:03:09 +0900,  
> Michael M. 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.

---

<div class="post-metadata">

**Author:** ![cornik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/43a26b/32.png) [@cornik](https://www.ruby-forum.com/u/cornik)\
**Post date:** [April 6, 2009, 7:25am UTC](https://www.ruby-forum.com/t/whats-wrong-with-these/164794/5 "2009-04-06T07:25:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cornik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/43a26b/32.png) [@cornik](https://www.ruby-forum.com/u/cornik)\
**Post date:** [April 6, 2009, 4:20am UTC](https://www.ruby-forum.com/t/whats-wrong-with-these/164794/6 "2009-04-06T04:20:33Z")

</div>

Hi,

At Mon, 6 Apr 2009 11:03:09 +0900,  
Michael M. 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’

---

<div class="post-metadata">

**Author:** ![cornik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/43a26b/32.png) [@cornik](https://www.ruby-forum.com/u/cornik)\
**Post date:** [April 6, 2009, 10:18am UTC](https://www.ruby-forum.com/t/whats-wrong-with-these/164794/7 "2009-04-06T10:18:35Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![cornik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/43a26b/32.png) [@cornik](https://www.ruby-forum.com/u/cornik)\
**Post date:** [April 6, 2009, 3:55pm UTC](https://www.ruby-forum.com/t/whats-wrong-with-these/164794/8 "2009-04-06T15:55:59Z")

</div>

On Sun, 05 Apr 2009 21:19:04 -0500, Nobuyoshi N. wrote:

> > guys?
> 
> require ‘tmpdir’

Yeah. The core rdoc on [http://www.ruby-doc.org/](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
