Resolving host OS environment variables

Hi All,

Noob here so I apologize in advance. I need to write the following
pseudo code in Ruby such that it will fully resolve the directory to
“c:\users\username\directory” on Windows, for example.

if HostOS=Windows
echo “%USERHOME%\directory”
elseif HOSTOS=MacOS
echo “~/directory”
endif

The OS part I found in the posting below, so that’s good, but can I
resolve the OS’s environment variables from within Ruby? I couldn’t find
an answer for that.

Thanks in advance,

Paul

determing what os is running
https://www.ruby-forum.com/topic/150942

Here’s the solution I eventually came up with.

@os = RbConfig::CONFIG[‘host_os’]
case
when @os.downcase.include?(‘mswin’) | @os.downcase.include?(‘mingw’)
| @os.downcase.include?(‘cygwin’)
homedir= ENV[‘USERPROFILE’]
mavenRepo = homedir + “\.m2\repository”
workspace = “C:\workspace\vault”
when @os.downcase.include?(‘darwin’) |
@os.downcase.include?(‘linux’)
homedir = “~”
mavenRepo = homedir + “/.m2/repository”
workspace = homedir + “/Documents/workspace/vault”
else
puts ‘You are not on a supported platform. exiting…’
print “unknown os: “” + @os + “”. Please email this error to
[email protected]
exit
end

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs