Hash#each
is an alias for Hash#each_pair
.
Calls the given block with each key-value pair; returns self
:
h = {foo: 0, bar: 1, baz: 2} h.each_pair {|key, value| puts "#{key}: #{value}"} # => {:foo=>0, :bar=>1, :baz=>2}
Output:
foo: 0 bar: 1 baz: 2
Returns a new Enumerator if no block given:
h = {foo: 0, bar: 1, baz: 2} e = h.each_pair # => #<Enumerator: {:foo=>0, :bar=>1, :baz=>2}:each_pair> h1 = e.each {|key, value| puts "#{key}: #{value}"} h1 # => {:foo=>0, :bar=>1, :baz=>2}
Output:
foo: 0 bar: 1 baz: 2
Yields each environment variable name and its value as a 2-element Array:
h = {} ENV.each_pair { |name, value| h[name] = value } # => ENV h # => {"bar"=>"1", "foo"=>"0"}
Returns an Enumerator
if no block given:
h = {} e = ENV.each_pair # => #<Enumerator: {"bar"=>"1", "foo"=>"0"}:each_pair> e.each { |name, value| h[name] = value } # => ENV h # => {"bar"=>"1", "foo"=>"0"}
Returns an IO
object representing the current file. This will be a File
object unless the current file is a stream such as STDIN.
For example:
ARGF.to_io #=> #<File:glark.txt> ARGF.to_io #=> #<IO:<STDIN>>
Iterates over each character of each file in ARGF
.
This method allows you to treat the files supplied on the command line as a single file consisting of the concatenation of each named file. After the last character of the first file has been returned, the first character of the second file is returned. The ARGF.filename
method can be used to determine the name of the file in which the current character appears.
If no block is given, an enumerator is returned instead.
Reads at most maxlen bytes from the ARGF
stream in non-blocking mode.
Returns the encoded quote character; used for parsing and writing; see {Option quote_char
}:
CSV.new('').quote_char # => "\""
Returns the value that determines whether headers are to be written; used for generating; see {Option write_headers
}:
CSV.new('').write_headers? # => nil
Serialization support for the object returned by _getobj_.
Reinitializes delegation from a serialized object.
Can be used to set eoutvar as described in ERB::new
. It’s probably easier to just use the constructor though, since calling this method requires the setup of an ERB
compiler object.
Returns true if the ipaddr is an IPv4-compatible IPv6 address.
Returns a new ipaddr built by converting the native IPv4 address into an IPv4-compatible IPv6 address.
Returns the names of the binding’s local variables as symbols.
def foo a = 1 2.times do |n| binding.local_variables #=> [:a, :n] end end
This method is the short version of the following code:
binding.eval("local_variables")
Returns true
if this is a lower triangular matrix.
Returns true
if this is an upper triangular matrix.
Hadamard product
Matrix[[1,2], [3,4]].hadamard_product(Matrix[[1,2], [3,2]]) # => 1 4 # 9 8
Private. Use Matrix#determinant
Returns the determinant of the matrix, using Bareiss’ multistep integer-preserving gaussian elimination. It has the same computational cost order O(n^3) as standard Gaussian elimination. Intermediate results are fraction free and of lower complexity. A matrix of Integers will have thus intermediate results that are also Integers, with smaller bignums (if any), while a matrix of Float
will usually have intermediate results with better precision.
Returns an angle with another vector. Result is within the [0..Math::PI].
Vector[1,0].angle_with(Vector[0,1]) # => Math::PI / 2
Creates an OptionParser::Switch
from the parameters. The parsed argument value is passed to the given block, where it can be processed.
See at the beginning of OptionParser
for some full examples.
params
can include the following elements:
One of the following:
:NONE, :REQUIRED, :OPTIONAL
Acceptable option argument format, must be pre-defined with OptionParser.accept
or OptionParser#accept
, or Regexp
. This can appear once or assigned as String
if not present, otherwise causes an ArgumentError
. Examples:
Float, Time, Array
[:text, :binary, :auto] %w[iso-2022-jp shift_jis euc-jp utf8 binary] { "jis" => "iso-2022-jp", "sjis" => "shift_jis" }
Specifies a long style switch which takes a mandatory, optional or no argument. It’s a string of the following form:
"--switch=MANDATORY" or "--switch MANDATORY" "--switch[=OPTIONAL]" "--switch"
Specifies short style switch which takes a mandatory, optional or no argument. It’s a string of the following form:
"-xMANDATORY" "-x[OPTIONAL]" "-x"
There is also a special form which matches character range (not full set of regular expression):
"-[a-z]MANDATORY" "-[a-z][OPTIONAL]" "-[a-z]"
Instead of specifying mandatory or optional arguments directly in the switch parameter, this separate parameter can be used.
"=MANDATORY" "=[OPTIONAL]"
Description string for the option.
"Run verbosely"
If you give multiple description strings, each string will be printed line by line.
Handler for the parsed argument value. Either give a block or pass a Proc
or Method
as an argument.