Helper method for grabbing elements from document
Like ‘take_while` except when it stops iterating, it also returns the line that caused it to stop
Returns the source encoding name as a string.
Returns the destination encoding name as a string.
Returns the source encoding name as a string.
Returns the destination encoding name as a string.
A pretty print for a pair of Hash
foo in bar ^^^^^^^^^^
foo => bar ^^^^^^^^^^
The line number in the source code where this AST’s text began.
The column number in the source code where this AST’s text began.
The line number in the source code where this AST’s text began.
The column number in the source code where this AST’s text began.
Fetch the leading comments of the value.
Configure the leading comments field for this repository and return self.
The default encoding for Ruby
files is UTF-8.
Build a diagnostic from the given prism parse error.
Build a diagnostic from the given prism parse warning.
Verifies each certificate in chain
has signed the following certificate and is valid for the given time
.
Returns the element of self
at offset index
if index
is in range; index
must be an integer-convertible object.
With the single argument index
and no block, returns the element at offset index
:
a = [:foo, 'bar', 2] a.fetch(1) # => "bar" a.fetch(1.1) # => "bar"
If index
is negative, counts from the end of the array:
a = [:foo, 'bar', 2] a.fetch(-1) # => 2 a.fetch(-2) # => "bar"
With arguments index
and default_value
(which may be any object) and no block, returns default_value
if index
is out-of-range:
a = [:foo, 'bar', 2] a.fetch(1, nil) # => "bar" a.fetch(3, :foo) # => :foo
With argument index
and a block, returns the element at offset index
if index is in range (and the block is not called); otherwise calls the block with index and returns its return value:
a = [:foo, 'bar', 2] a.fetch(1) {|index| raise 'Cannot happen' } # => "bar" a.fetch(50) {|index| "Value for #{index}" } # => "Value for 50"
Related: see Methods for Fetching.
With a block given, iterates over the elements of self
, passing each element to the block; returns self
:
a = [:foo, 'bar', 2] a.each {|element| puts "#{element.class} #{element}" }
Output:
Symbol foo String bar Integer 2
Allows the array to be modified during iteration:
a = [:foo, 'bar', 2] a.each {|element| puts element; a.clear if element.to_s.start_with?('b') }
Output:
foo bar
With no block given, returns a new Enumerator
.
Related: see Methods for Iterating.
Returns the element from self
found by a binary search, or nil
if the search found no suitable element.
See Binary Searching.
Related: see Methods for Fetching.
Returns a 1-character string containing the character represented by the value of self
, according to the given encoding
.
65.chr # => "A" 0.chr # => "\x00" 255.chr # => "\xFF" string = 255.chr(Encoding::UTF_8) string.encoding # => Encoding::UTF_8
Raises an exception if self
is negative.
Related: Integer#ord
.