Module: Env

Extended by:
Variables
Defined in:
lib/env/env.rb,
lib/env/version.rb,
lib/env/variables.rb

Defined Under Namespace

Modules: Variables

Constant Summary collapse

VERSION =

env version

"0.3.0"

Class Method Summary collapse

Methods included from Variables

browser, columns, debug?, editor, env, home, host_name, lang, ld_library_paths, lines, parse_paths, paths, shell, shell_name, terminal, timezone, user

Class Method Details

.[](name) ⇒ String?

Provides direct access to the environment variables.

Examples:

Env['SHELL']
# => "/bin/bash"

Parameters:

  • name (String, Symbol)

    The name of the environment variable.

Returns:

  • (String, nil)

    The value of the environment variable.



19
20
21
# File 'lib/env/env.rb', line 19

def Env.[](name)
  env[name.to_s]
end

.[]=(name, value) ⇒ String

Sets an environment variable.

Parameters:

  • name (String, Symbol)

    The name of the environment variable.

  • value (Object)

    The value of the environment variable.

Returns:

  • (String)

    The String value of the environment variable.



35
36
37
# File 'lib/env/env.rb', line 35

def Env.[]=(name,value)
  env[name.to_s] = value.to_s
end

.const_missing(name) ⇒ String? (protected)

Provides transparent access to the environment variables.

Examples:

Env::SHELL
# => "/bin/bash"

Parameters:

  • name (Symbol)

    The name of the environment variable.

Returns:

  • (String, nil)

    The value of the environment variable.



54
55
56
# File 'lib/env/env.rb', line 54

def Env.const_missing(name)
  Env[name.to_s]
end

.method_missing(name, *arguments, &block) ⇒ String? (protected)

Provides transparent access to the environment variables.

Examples:

Env.shell
# => "/bin/bash"
Env.shell = '/bin/zsh'
# => "/bin/zsh"

Parameters:

  • name (Symbol)

    The name of the environment variable.

Returns:

  • (String, nil)

    The value of the environment variable.



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/env/env.rb', line 75

def Env.method_missing(name,*arguments,&block)
  name = name.to_s

  if (arguments.length == 1 && name[-1..-1] == '=')
    name.chop!
    name.upcase!

    return Env[name] = arguments.first
  elsif arguments.empty?
    name.upcase!

    return Env[name]
  end

  super(name,*arguments,&block)
end