Finding user’s home directory can be useful especially for config files. Ruby 1.9.2 introduced
Dir.home method. So to find a config file present in home directory all you have to do is:
Dir.home depends on
$HOME env variable. If it’s not set then it throws an error.
1 2 3 4 5 6
Above error can be fixed if we know the current username. i.e.,
1 2 3
So how do we find the username? Operating system can tell us and ruby has an
etc standard library.
1 2 3 4
Above technique works on Linux and OSX. But it doesn’t work on windows.