Dir.mktmpdir in IRB vs Pry

When I call Dir.mktmpdir in Pry, it works. I get

=> “/tmp/d20131019-7589-9g9zxs”

But when I call it in IRB, it doesn’t. I get

NoMethodError: undefined method `mktmpdir’ for Dir:Class

Other Dir methods work in IRB. Why not this one? Or is Pry loading
something that IRB isn’t?

Ruby noob here, sorry if this is a noob question.

On 2013-10-19, at 4:51 PM, Jack D. [email protected] wrote:

Ruby noob here, sorry if this is a noob question.

A noob question, but you are on the right course:

ratdog:~ mike$ irb
irb(main):001:0> Dir.mktmpdir
NoMethodError: undefined method mktmpdir' for Dir:Class from (irb):1 from /Users/mike/.rbenv/versions/2.0.0-p247/bin/irb:12:in
irb(main):002:0> require ‘tmpdir’
=> true
irb(main):003:0> Dir.mktmpdir
=>
“/var/folders/f3/6zk_yypd73jc88n1p6ww2f_00000gn/T/d20131019-5591-1dprrhs”

How to tell that is the right thing to do from Pry?

mike$ pry
[1] pry(main)> cd Dir
[2] pry(Dir):1> $ mktmpdir

From: /Users/mike/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/tmpdir.rb @
line 84:
Owner: #Class:Dir
Visibility: public
Number of lines: 16

def Dir.mktmpdir(prefix_suffix=nil, *rest)
path = Tmpname.create(prefix_suffix || “d”, *rest) {|n| mkdir(n,
0700)}
if block_given?
begin
yield path
ensure
stat = File.stat(File.dirname(path))
if stat.world_writable? and !stat.sticky?
raise ArgumentError, “parent directory is world writable but not
sticky”
end
FileUtils.remove_entry path
end
else
path
end
end

so tmpdir.rb seems like a good suspect, so my first guess was to
“require ‘tmpdir’”

Hope this helps,

Mike

Mike S. [email protected]
http://www.stok.ca/~mike/

The “`Stok’ disclaimers” apply.

On Oct 19, 2013, at 1:51 PM, Jack D. [email protected] wrote:

When I call Dir.mktmpdir in Pry, it works. I get

=> “/tmp/d20131019-7589-9g9zxs”

But when I call it in IRB, it doesn’t. I get

NoMethodError: undefined method `mktmpdir’ for Dir:Class

$ irb
irb(main):001:0> Dir.mktmpdir
NoMethodError: undefined method `mktmpdir’ for Dir:Class
from (irb):1
from :0
irb(main):002:0> require ‘tmpdir’
=> true
irb(main):003:0> Dir.mktmpdir
=>
“/var/folders/20/gc77rfg10hq5q77nlzslx6l40000gn/T/d20131019-10680-jj4nhc”

Ah! Thanks, I had a feeling Pry was being extra helpful.