Ruby Language

Environment Variables

Syntax#

  • ENV[variable_name]
  • ENV.fetch(variable_name, default_value)

Remarks#

Let get user profile path in a dynamic way for scripting under windows

Sample to get user profile path

# will retrieve my home path
ENV['HOME'] # => "/Users/username"

# will try retrieve the 'FOO' environment variable. If failed, will get 'bar'
ENV.fetch('FOO', 'bar')

This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow