Module: Nuggets::Env::UserHomeMixin
- Defined in:
- lib/nuggets/env/user_home_mixin.rb
Instance Method Summary collapse
-
#user_home(default = ::File::ALT_SEPARATOR ? 'C:/' : '/') ⇒ Object
call-seq: ENV.user_home() => aString.
Instance Method Details
#user_home(default = ::File::ALT_SEPARATOR ? 'C:/' : '/') ⇒ Object
call-seq:
ENV.user_home([default]) => aString
Returns the user’s home directory, or default if it could not be found.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/nuggets/env/user_home_mixin.rb', line 35 def user_home(default = ::File::ALT_SEPARATOR ? 'C:/' : '/') begin return ::Dir.home rescue ::ArgumentError # "couldn't find HOME environment -- expanding `~'" end if ::Dir.respond_to?(:home) %w[HOME HOMEDRIVE:HOMEPATH USERPROFILE APPDATA].each { |key| home = values_at(*key.split(':')).join return home.gsub(/\\/, '/') if home && !home.empty? } begin ::File.('~') rescue ::ArgumentError default end end |