Dispatch enter and leave events for MatchRequiredNode
nodes and continue walking the tree.
Dispatch enter and leave events for MatchWriteNode
nodes and continue walking the tree.
Inspect a CaseMatchNode
node.
Inspect a MatchRequiredNode
node.
Inspect a MatchWriteNode
node.
returns match status of CSI/SS3 sequence and matched length
Create a new MatchLastLineNode
node.
Compile a InterpolatedMatchLastLineNode
node
Dispatch enter and leave events for InterpolatedMatchLastLineNode
nodes and continue walking the tree.
Inspect a InterpolatedMatchLastLineNode
node.
Copy a InterpolatedMatchLastLineNode
node
@api private
Does this dependency request match spec
?
NOTE: matches_spec?
matches prerelease versions. See also match?
With a block given, calls the block with each repeated permutation of length size
of the elements of self
; each permutation is an array; returns self
. The order of the permutations is indeterminate.
If a positive integer argument size
is given, calls the block with each size
-tuple repeated permutation of the elements of self
. The number of permutations is self.size**size
.
Examples:
size
is 1:
p = [] [0, 1, 2].repeated_permutation(1) {|permutation| p.push(permutation) } p # => [[0], [1], [2]]
size
is 2:
p = [] [0, 1, 2].repeated_permutation(2) {|permutation| p.push(permutation) } p # => [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2]]
If size
is zero, calls the block once with an empty array.
If size
is negative, does not call the block:
[0, 1, 2].repeated_permutation(-1) {|permutation| fail 'Cannot happen' }
With no block given, returns a new Enumerator
.
Related: see Methods for Combining.
With a block given, calls the block with each repeated combination of length size
of the elements of self
; each combination is an array; returns self
. The order of the combinations is indeterminate.
If a positive integer argument size
is given, calls the block with each size
-tuple repeated combination of the elements of self
. The number of combinations is (size+1)(size+2)/2
.
Examples:
size
is 1:
c = [] [0, 1, 2].repeated_combination(1) {|combination| c.push(combination) } c # => [[0], [1], [2]]
size
is 2:
c = [] [0, 1, 2].repeated_combination(2) {|combination| c.push(combination) } c # => [[0, 0], [0, 1], [0, 2], [1, 1], [1, 2], [2, 2]]
If size
is zero, calls the block once with an empty array.
If size
is negative, does not call the block:
[0, 1, 2].repeated_combination(-1) {|combination| fail 'Cannot happen' }
With no block given, returns a new Enumerator
.
Related: see Methods for Combining.
With no block given, returns a new array containing the elements of self
at the offsets specified by indexes
. Each of the indexes
must be an integer-convertible object:
a = [:foo, :bar, :baz] a.fetch_values(2, 0) # => [:baz, :foo] a.fetch_values(2.1, 0) # => [:baz, :foo] a.fetch_values # => []
For a negative index, counts backwards from the end of the array:
a.fetch_values(-2, -1) # [:bar, :baz]
When no block is given, raises an exception if any index is out of range.
With a block given, for each index:
If the index is in range, uses an element of self
(as above).
Otherwise, calls the block with the index and uses the block’s return value.
Example:
a = [:foo, :bar, :baz] a.fetch_values(1, 0, 42, 777) { |index| index.to_s } # => [:bar, :foo, "42", "777"]
Related: see Methods for Fetching.
Calls the given block with each successive character from self
; returns self
:
'hello'.each_char {|char| print char, ' ' } print "\n" 'тест'.each_char {|char| print char, ' ' } print "\n" 'こんにちは'.each_char {|char| print char, ' ' } print "\n"
Output:
h e l l o т е с т こ ん に ち は
Returns an enumerator if no block is given.
Like Dir.foreach
, except that entries '.'
and '..'
are not included.
Calls the block with each entry name in self
except '.'
and '..'
:
dir = Dir.new('/example') dir.each_child {|entry_name| p entry_name }
Output:
"config.h" "lib" "main.rb"
If no block is given, returns an enumerator.
Returns the locale charmap name. It returns nil if no appropriate information.
Debian GNU/Linux LANG=C Encoding.locale_charmap #=> "ANSI_X3.4-1968" LANG=ja_JP.EUC-JP Encoding.locale_charmap #=> "EUC-JP" SunOS 5 LANG=C Encoding.locale_charmap #=> "646" LANG=ja Encoding.locale_charmap #=> "eucJP"
The result is highly platform dependent. So Encoding.find(Encoding.locale_charmap)
may cause an error. If you need some encoding object even for unknown locale, Encoding.find
(“locale”) can be used.
Calls the given block with each character in the stream; returns self
. See Character IO.
f = File.new('t.rus') a = [] f.each_char {|c| a << c.ord } a # => [1090, 1077, 1089, 1090] f.close
Returns an Enumerator
if no block is given.
Related: IO#each_byte
, IO#each_codepoint
.