You can use the backtick ` in Ruby to run a command line against the system. It will then return the result of the call.
Here's the official description at Ruby-Doc.org
Returns the standard output of running cmd in a subshell. The built-in
syntax %x{...} uses this method. Sets $? to the process status.
`echo` #=> 'ECHO is on.' if ran on Windows
In Windows, there are special variables you can use to gather information such as a username:
echo %username%
Hence, you can use these two to gather the location of the user's My Documents folder (provided they are on Windows).
# Tested on Windows XP and 7
my_documents = File.join(`echo %userprofile%`.chomp, "My Documents")
Note:
There is also a method in Ruby that makes system calls which is system
. However, this returns a boolean which will not work in your case.
Also note that this solution will only work on Windows.