Cross-platform means of getting user's home directory in Ruby?

davetron5000 picture davetron5000 · Nov 16, 2010 · Viewed 25.3k times · Source

Java has the convienient System.getProperty("user.home") to get the user's "home" directory in a platform-independent way. What's the equivalent in Ruby? I don't have a Windows box to play around with, and I feel like relying on tildes in filenames isn't the cleanest way. Are there alternatives?

Answer

Pioz picture Pioz · Sep 25, 2011

With Ruby 1.9 and above you can use Dir.home.