Logo

Allolexicon

  • Email Me
  • Photo Blog
  • Politics & Culture
  • Portfolio
  • Franscrollow
  • Archive
  • RSS

Creating temporary directories in Ruby

How can I easily create temporary directories (and files) in Ruby that won’t break the cross-platform compatibility of my script?

It took a bit of digging to locate this information, so I’ll post it here in the hope that the search engines will make it easier to find for the next person with this question.

The answer is to use Dir.mktmpdir, which will magically appear in the Dir class if you require ‘tmpdir’ in your script. Basically, tmpdir adds methods to the existing core Dir class. It’s apparently been part of Ruby since 1.8.6.

I would recommend using this standard library rather than rolling your own because it lets your operating system worry about where to locate the temporary directory.

    • #gem
    • #ruby
    • #Development
  • 6 months ago
  • 55
  • Permalink
  • Share
    Tweet

55 Notes/ Hide

  1. hamiltonok4 liked this
  2. salvadorto834 liked this
  3. allolexicon posted this
← Previous • Next →

Me, Elsewhere

  • @allolex on Twitter
  • allolex on Vimeo
  • DamonAllenDavison on Youtube
  • allolex on Flickr
  • allolex on github

Twitter

loading tweets…

  • RSS
  • Random
  • Archive
  • Mobile

Copyright ©2011-2012 Damon Allen Davison. Effector Theme by Carlo Franco.

Powered by Tumblr