123456789_123456789_123456789_123456789_123456789_

Class: ENV

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, ::Enumerable
Inherits: Object
Defined in: hash.c,
hash.c

Overview

ENV is a hash-like accessor for environment variables.

Class Attribute Summary

::Enumerable - Extended

all?

Passes each element of the collection to the given block.

any?

Passes each element of the collection to the given block.

none?

Passes each element of the collection to the given block.

one?

Passes each element of the collection to the given block.

Class Method Summary

::Enumerable - Extended

chunk

Enumerates over the items, chunking them together based on the return value of the block.

chunk_while

Creates an enumerator for each chunked elements.

collect

Alias for Enumerable#map.

collect_concat
count

Returns the number of items in enum through enumeration.

cycle

Calls block for each element of enum repeatedly n times or forever if none or nil is given.

detect

Alias for Enumerable#find.

drop

Drops first n elements from enum, and returns rest elements in an array.

drop_while

Drops elements up to, but not including, the first element for which the block returns nil or false and returns an array containing the remaining elements.

each_cons

Iterates the given block for each array of consecutive <n> elements.

each_entry

Calls block once for each element in self, passing that element as a parameter, converting multiple values from yield to an array.

each_slice

Iterates the given block for each slice of <n> elements.

each_with_index

Calls block with two arguments, the item and its index, for each item in enum.

each_with_object

Iterates the given block for each element with an arbitrary object given, and returns the initially given object.

entries

Alias for Enumerable#to_a.

find

Passes each entry in enum to block.

find_all
find_index

Compares each entry in enum with value or passes to block.

first

Returns the first element, or the first n elements, of the enumerable.

flat_map

Returns a new array with the concatenated results of running block once for every element in enum.

grep

Returns an array of every element in enum for which Pattern === element.

grep_v

Inverted version of Enumerable#grep.

group_by

Groups the collection by result of the block.

include?
inject

Combines all elements of enum by applying a binary operation, specified by a block or a symbol that names a method or operator.

lazy

Returns a lazy enumerator, whose methods map/collect, flat_map/collect_concat, select/find_all, reject, grep, grep_v, zip, take, take_while, drop, and drop_while enumerate values only on an as-needed basis.

map

Returns a new array with the results of running block once for every element in enum.

max

Returns the object in enum with the maximum value.

max_by

Returns the object in enum that gives the maximum value from the given block.

member?

Returns true if any member of enum equals obj.

min

Returns the object in enum with the minimum value.

min_by

Returns the object in enum that gives the minimum value from the given block.

minmax

Returns a two element array which contains the minimum and the maximum value in the enumerable.

minmax_by

Returns a two element array containing the objects in enum that correspond to the minimum and maximum values respectively from the given block.

partition

Returns two arrays, the first containing the elements of enum for which the block evaluates to true, the second containing the rest.

reduce
reject

Returns an array for all elements of enum for which the given block returns false.

reverse_each

Builds a temporary array and traverses that array in reverse order.

select

Returns an array containing all elements of enum for which the given block returns a true value.

slice_after

Creates an enumerator for each chunked elements.

slice_before

Creates an enumerator for each chunked elements.

slice_when

Creates an enumerator for each chunked elements.

sort

Returns an array containing the items in enum sorted, either according to their own <=> method, or by using the results of the supplied block.

sort_by

Sorts enum using a set of keys generated by mapping the values in enum through the given block.

take

Returns first n elements from enum.

take_while

Passes elements to the block until the block returns nil or false, then stops iterating and returns an array of all prior elements.

to_a

Returns an array containing the items in enum.

to_h

Returns the result of interpreting enum as a list of [key, value] pairs.

zip

Takes one element from enum and merges corresponding elements from each args.

Class Attribute Details

.empty?Boolean (readonly)

Returns true when there are no environment variables

Class Method Details

.[](name) ⇒ value

Retrieves the value for environment variable name as a ::String. Returns nil if the named variable does not exist.

.[]=(name, value) .store(name, value) ⇒ value
Also known as: .store

Sets the environment variable name to value. If the value given is nil the environment variable is deleted. name must be a string.

.assoc(name) ⇒ Array?

Returns an ::Array of the name and value of the environment variable with name or nil if the name cannot be found.

.clear

Removes every environment variable.

.delete(name) ⇒ value .delete(name) {|name| ... } ⇒ value

Deletes the environment variable with name and returns the value of the variable. If a block is given it will be called when the named environment does not exist.

.delete_if {|name, value| ... } ⇒ Hash .delete_ifEnumerator

Deletes every environment variable for which the block evaluates to true.

If no block is given an enumerator is returned instead.

.each {|name, value| ... } ⇒ Hash .eachEnumerator .each_pair {|name, value| ... } ⇒ Hash .each_pairEnumerator
Also known as: .each_pair

Yields each environment variable name and value.

If no block is given an ::Enumerator is returned.

.each_key {|name| ... } ⇒ Hash .each_keyEnumerator

Yields each environment variable name.

An Enumerator is returned if no block is given.

.each {|name, value| ... } ⇒ Hash .eachEnumerator .each_pair {|name, value| ... } ⇒ Hash .each_pairEnumerator

Alias for .each.

.each_value {|value| ... } ⇒ Hash .each_valueEnumerator

Yields each environment variable value.

An Enumerator is returned if no block was given.

.fetch(name) ⇒ value .fetch(name, default) ⇒ value .fetch(name) {|missing_name| ... } ⇒ value

Retrieves the environment variable name.

If the given name does not exist and neither default nor a block a provided an ::IndexError is raised. If a block is given it is called with the missing name to provide a value. If a default value is given it will be returned when no block is given.

.key?(name) ⇒ Boolean .include?(name) ⇒ Boolean .has_key?(name) ⇒ Boolean .member?(name) ⇒ Boolean

Alias for .key?.

.value?(value) ⇒ Boolean .has_value?(value) ⇒ Boolean

Alias for .value?.

.key?(name) ⇒ Boolean .include?(name) ⇒ Boolean .has_key?(name) ⇒ Boolean .member?(name) ⇒ Boolean

Alias for .key?.

.index(value) ⇒ key

Deprecated method that is equivalent to .key

.inspectString

Returns the contents of the environment as a ::String.

.invertHash

Returns a new hash created by using environment variable names as values and values as names.

.keep_if {|name, value| ... } ⇒ Hash .keep_ifEnumerator

Deletes every environment variable where the block evaluates to false.

Returns an enumerator if no block was given.

.key(value) ⇒ name

Returns the name of the environment variable with value. If the value is not found nil is returned.

.key?(name) ⇒ Boolean .include?(name) ⇒ Boolean .has_key?(name) ⇒ Boolean .member?(name) ⇒ Boolean
Also known as: .include?, .member?, .has_key?

Returns true if there is an environment variable with the given name.

.keysArray

Returns every environment variable name in an ::Array

.length .size
Also known as: .size

Returns the number of environment variables.

.key?(name) ⇒ Boolean .include?(name) ⇒ Boolean .has_key?(name) ⇒ Boolean .member?(name) ⇒ Boolean

Alias for .key?.

.rassoc(value)

Returns an ::Array of the name and value of the environment variable with value or nil if the value cannot be found.

.rehash

Re-hashing the environment variables does nothing. It is provided for compatibility with ::Hash.

.reject {|name, value| ... } ⇒ Hash .rejectEnumerator

Same as ENV#delete_if, but works on (and returns) a copy of the environment.

.reject! {|name, value| ... } ⇒ ENV? .reject!Enumerator

Equivalent to ENV#delete_if but returns nil if no changes were made.

Returns an ::Enumerator if no block was given.

.replace(hash) ⇒ ENV

Replaces the contents of the environment variables with the contents of hash.

.select {|name, value| ... } ⇒ Hash .selectEnumerator

Returns a copy of the environment for entries where the block returns true.

Returns an ::Enumerator if no block was given.

.select! {|name, value| ... } ⇒ ENV? .select!Enumerator

Equivalent to ENV#keep_if but returns nil if no changes were made.

.shiftArray?

Removes an environment variable name-value pair from ENV and returns it as an ::Array. Returns nil if when the environment is empty.

.length .size

Alias for .length.

.[]=(name, value) .store(name, value) ⇒ value

Alias for .[]=.

.to_aArray

Converts the environment variables into an array of names and value arrays.

ENV.to_a # => [["TERM", "xterm-color"], ["SHELL", "/bin/bash"], ...]

.to_hashHash .to_hHash
Also known as: .to_hash

Creates a hash with a copy of the environment variables.

.to_hashHash .to_hHash

Alias for .to_h.

.to_sENV

Returns “ENV”

.update(hash) ⇒ Hash .update(hash) {|name, old_value, new_value| ... } ⇒ Hash

Adds the contents of hash to the environment variables. If no block is specified entries with duplicate keys are overwritten, otherwise the value of each duplicate name is determined by calling the block with the key, its value from the environment and its value from the hash.

.value?(value) ⇒ Boolean .has_value?(value) ⇒ Boolean
Also known as: .has_value?

Returns true if there is an environment variable with the given value.

.valuesArray

Returns every environment variable value as an ::Array

.values_at(name, ...) ⇒ Array

Returns an array containing the environment variable values associated with the given names. See also .select.