How to get a temp directory in any OS with Ruby

How to get a temp directory in any OS with Ruby

I needed this over the weekend and the existing online help is less than helpful. As it turns out, just like with everything I try to do in Ruby, the solution is simple.

require 'tmpdir'
temp = Dir.tmpdir() 
puts temp #C:/Users/Robert/AppData/Local/Temp

This is all built into Ruby, you don't need to install any gems or anything.

Robert Greiner

Robert Greiner

Professional optimist. Passionate about cultivating high-performing teams @ scale by integrating the timeless wisdom of the past with the marvel of today's emergent technology in a practical way.

View Comments
Next Post

Using LINQ to sum up a list of numbers

Previous Post

NumberText: Converting numbers into words in C#

Subscribe for free

Subscribe to my newsletter and get the latest posts delivered right to your inbox for free. I don't spam and your email won't be shared with third-parties.

Thanks for subscribing!

Check your inbox to confirm your subscription.

Please enter a valid email address!