Returns true
if the given value is present for some key in hsh.
h = { "a" => 100, "b" => 200 } h.value?(100) #=> true h.value?(999) #=> false
Returns all environment variable values in an Array:
ENV.replace('foo' => '0', 'bar' => '1') ENV.values # => ['1', '0']
The order of the values is OS-dependent. See About Ordering.
Returns the empty Array
if ENV
is empty:
ENV.clear ENV.values # => []
Returns true
if there is an environment variable with the given value
.
Reads at most maxlen bytes from the ARGF
stream.
If the optional outbuf argument is present, it must reference a String
, which will receive the data. The outbuf will contain only the received data after the method call even if it is not empty at the beginning.
It raises EOFError
on end of ARGF
stream. Since ARGF
stream is a concatenation of multiple files, internally EOF is occur for each file. ARGF.readpartial
returns empty strings for EOFs except the last one and raises EOFError
for the last one.
Returns the current offset (in bytes) of the current file in ARGF
.
ARGF.pos #=> 0 ARGF.gets #=> "This is line one\n" ARGF.pos #=> 17
This method will return a CSV
instance, just like CSV::new()
, but the instance will be cached and returned for all future calls to this method for the same data
object (tested by Object#object_id()
) with the same options
.
If a block is given, the instance is passed to the block and the return value becomes the return value of the block.
A shortcut for:
CSV.read( path, { headers: true, converters: :numeric, header_converters: :symbol }.merge(options) )
Evaluates the Ruby expression(s) in string, in the binding’s context. If the optional filename and lineno parameters are present, they will be used when reporting syntax errors.
def get_binding(param) binding end b = get_binding("hello") b.eval("param") #=> "hello"
Creates a matrix where the diagonal elements are composed of values
.
Matrix.diagonal(9, 5, -3) => 9 0 0 0 5 0 0 0 -3
Creates an n
by n
diagonal matrix where each diagonal element is value
.
Matrix.scalar(2, 5) => 5 0 0 5
Create a matrix by stacking matrices vertically
x = Matrix[[1, 2], [3, 4]] y = Matrix[[5, 6], [7, 8]] Matrix.vstack(x, y) # => Matrix[[1, 2], [3, 4], [5, 6], [7, 8]]
Create a matrix by stacking matrices horizontally
x = Matrix[[1, 2], [3, 4]] y = Matrix[[5, 6], [7, 8]] Matrix.hstack(x, y) # => Matrix[[1, 2, 5, 6], [3, 4, 7, 8]]
Returns a matrix that is the result of iteration of the given block over all elements of the matrix. Elements can be restricted by passing an argument:
:all (default): yields all elements
:diagonal: yields only elements on the diagonal
:off_diagonal: yields all elements except on the diagonal
:lower: yields only elements on or below the diagonal
:strict_lower: yields only elements below the diagonal
:strict_upper: yields only elements above the diagonal
:upper: yields only elements on or above the diagonal Matrix[ [1,2], [3,4] ].collect { |e| e**2 }
=> 1 4 9 16
Invokes the given block for each element of matrix, replacing the element with the value returned by the block. Elements can be restricted by passing an argument:
:all (default): yields all elements
:diagonal: yields only elements on the diagonal
:off_diagonal: yields all elements except on the diagonal
:lower: yields only elements on or below the diagonal
:strict_lower: yields only elements below the diagonal
:strict_upper: yields only elements above the diagonal
:upper: yields only elements on or above the diagonal
Returns true
if this is a diagonal matrix. Raises an error if matrix is not square.
Returns true
if this is a normal matrix. Raises an error if matrix is not square.
Returns true
if this is an orthogonal matrix Raises an error if matrix is not square.
Returns true
if this is a permutation matrix Raises an error if matrix is not square.
Returns true
if all entries of the matrix are real.
Returns true
if this is a unitary matrix Raises an error if matrix is not square.
Returns a new matrix resulting by stacking horizontally the receiver with the given matrices
x = Matrix[[1, 2], [3, 4]] y = Matrix[[5, 6], [7, 8]] x.hstack(y) # => Matrix[[1, 2, 5, 6], [3, 4, 7, 8]]
Returns a new matrix resulting by stacking vertically the receiver with the given matrices
x = Matrix[[1, 2], [3, 4]] y = Matrix[[5, 6], [7, 8]] x.vstack(y) # => Matrix[[1, 2], [3, 4], [5, 6], [7, 8]]
Returns the real part of the matrix.
Matrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]] => 1+2i i 0 1 2 3 Matrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]].real => 1 0 0 1 2 3