Module: Env

Defined in:
lib/riel/env.rb

Overview

-*- ruby -*-

Constant Summary collapse

REGEXP =

matches single and double quoted strings:

/                    # either:
   ([\"\'])          #     start with a quote, and save it ($1)
   (                 #     save this ($2)
     (?:             #         either (and don't save this):
         \\.         #             any escaped character
       |             #         or
         [^\1\\]     #             anything that is not a quote ($1), and is not a backslash
     )*?             #         only up to the next quote
   )                 #         end of $2
   \1                #     end with the same quote we started with
 |                   # or
   (:?\S+)           #     plain old nonwhitespace
/x

Class Method Summary collapse

Class Method Details

.home_directoryObject

Returns the home directory, for both Unix and Windows.



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/riel/env.rb', line 6

def self.home_directory
  if hm = ENV["HOME"]
    hm
  else
    hd = ENV["HOMEDRIVE"]
    hp = ENV["HOMEPATH"]
    if hd || hp
      (hd || "") + (hp || "\\")
    else
      nil
    end
  end
end

.split(varname) ⇒ Object

Reads the environment variable, splitting it according to its quoting.



39
40
41
42
43
44
45
# File 'lib/riel/env.rb', line 39

def self.split varname
  if v = ENV[varname]
    v.scan(REGEXP).collect { |x| x[1] || x[2] }
  else
    []
  end
end