Module: Nuggets::Env::UserHomeMixin

Defined in:
lib/nuggets/env/user_home_mixin.rb

Instance Method Summary collapse

Instance Method Details

#user_home(default = ::File::ALT_SEPARATOR ? 'C:/' : '/') ⇒ Object

call-seq:

ENV.user_home => aString

Finds the user’s home directory. Stolen from RubyGems ;-)



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/nuggets/env/user_home_mixin.rb', line 36

def user_home(default = ::File::ALT_SEPARATOR ? 'C:/' : '/')
  %w[HOME USERPROFILE].each { |homekey|
    home = self[homekey]
    return home if home
  }

  if drive = self['HOMEDRIVE'] and path = self['HOMEPATH']
    return "#{drive}:#{path}"
  end

  begin
    ::File.expand_path('~')
  rescue ArgumentError
    default
  end
end