Results for: "Psych"

Enters exclusive section and executes the block. Leaves the exclusive section automatically when the block exits. See example under MonitorMixin.

See Thread::Mutex#synchronize

Obtains a lock, runs the block, and releases the lock when the block completes. See the example under Thread::Mutex.

No documentation available

Should be implemented by a extended class.

tsort_each_child is used to iterate for child nodes of node.

See Zlib::GzipReader documentation for a description.

Iterate all direct child instruction sequences. Iteration order is implementation/version defined so that people should not rely on the order.

No documentation available

Checks the scheme v component against the URI::Parser Regexp for :SCHEME.

No documentation available
No documentation available
No documentation available

Verifies each certificate in chain has signed the following certificate and is valid for the given time.

Returns the element at offset index.

With the single Integer argument index, returns the element at offset index:

a = [:foo, 'bar', 2]
a.fetch(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, returns the element at offset index if index is in range, otherwise returns default_value:

a = [:foo, 'bar', 2]
a.fetch(1, nil) # => "bar"

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"

Iterates over array elements.

When a block given, passes each successive array 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

When no block given, returns a new Enumerator:

a = [:foo, 'bar', 2]

e = a.each
e # => #<Enumerator: [:foo, "bar", 2]:each>
a1 = e.each {|element|  puts "#{element.class} #{element}" }

Output:

Symbol foo
String bar
Integer 2

Related: each_index, reverse_each.

When called with positive Integer argument count and a block, calls the block with each element, then does so again, until it has done so count times; returns nil:

output = []
[0, 1].cycle(2) {|element| output.push(element) } # => nil
output # => [0, 1, 0, 1]

If count is zero or negative, does not call the block:

[0, 1].cycle(0) {|element| fail 'Cannot happen' } # => nil
[0, 1].cycle(-1) {|element| fail 'Cannot happen' } # => nil

When a block is given, and argument is omitted or nil, cycles forever:

# Prints 0 and 1 forever.
[0, 1].cycle {|element| puts element }
[0, 1].cycle(nil) {|element| puts element }

When no block is given, returns a new Enumerator:

[0, 1].cycle(2) # => #<Enumerator: [0, 1]:cycle(2)>
[0, 1].cycle # => # => #<Enumerator: [0, 1]:cycle>
[0, 1].cycle.first(5) # => [0, 1, 0, 1, 0]

Returns an element from self selected by a binary search.

See Binary Searching.

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.

Returns a MatchData object (or nil) based on self and the given pattern.

Note: also updates Global Variables at Regexp.

With no block given, returns the computed matchdata:

'foo'.match('f') # => #<MatchData "f">
'foo'.match('o') # => #<MatchData "o">
'foo'.match('x') # => nil

If Integer argument offset is given, the search begins at index offset:

'foo'.match('f', 1) # => nil
'foo'.match('o', 1) # => #<MatchData "o">

With a block given, calls the block with the computed matchdata and returns the block’s return value:

'foo'.match(/o/) {|matchdata| matchdata } # => #<MatchData "o">
'foo'.match(/x/) {|matchdata| matchdata } # => nil
'foo'.match(/f/, 1) {|matchdata| matchdata } # => nil

Returns true or false based on whether a match is found for self and pattern.

Note: does not update Global Variables at Regexp.

Computes regexp by converting pattern (if not already a Regexp).

regexp = Regexp.new(pattern)

Returns true if self+.match(regexp) returns a MatchData object, false otherwise:

'foo'.match?(/o/) # => true
'foo'.match?('o') # => true
'foo'.match?(/x/) # => false

If Integer argument offset is given, the search begins at index offset:

'foo'.match?('f', 1) # => false
'foo'.match?('o', 1) # => true

Returns a string containing the first character of self:

s = 'foo' # => "foo"
s.chr     # => "f"

Returns an array of the characters in self:

'hello'.chars     # => ["h", "e", "l", "l", "o"]
'тест'.chars      # => ["т", "е", "с", "т"]
'こんにちは'.chars # => ["こ", "ん", "に", "ち", "は"]

Returns a new string copied from self, with trailing characters possibly removed.

Removes "\r\n" if those are the last two characters.

"abc\r\n".chop      # => "abc"
"тест\r\n".chop     # => "тест"
"こんにちは\r\n".chop # => "こんにちは"

Otherwise removes the last character if it exists.

'abcd'.chop     # => "abc"
'тест'.chop     # => "тес"
'こんにちは'.chop # => "こんにち"
''.chop         # => ""

If you only need to remove the newline separator at the end of the string, String#chomp is a better alternative.

Returns a new string copied from self, with trailing characters possibly removed:

When line_sep is "\n", removes the last one or two characters if they are "\r", "\n", or "\r\n" (but not "\n\r"):

$/                    # => "\n"
"abc\r".chomp         # => "abc"
"abc\n".chomp         # => "abc"
"abc\r\n".chomp       # => "abc"
"abc\n\r".chomp       # => "abc\n"
"тест\r\n".chomp      # => "тест"
"こんにちは\r\n".chomp  # => "こんにちは"

When line_sep is '' (an empty string), removes multiple trailing occurrences of "\n" or "\r\n" (but not "\r" or "\n\r"):

"abc\n\n\n".chomp('')           # => "abc"
"abc\r\n\r\n\r\n".chomp('')     # => "abc"
"abc\n\n\r\n\r\n\n\n".chomp('') # => "abc"
"abc\n\r\n\r\n\r".chomp('')     # => "abc\n\r\n\r\n\r"
"abc\r\r\r".chomp('')           # => "abc\r\r\r"

When line_sep is neither "\n" nor '', removes a single trailing line separator if there is one:

'abcd'.chomp('d')  # => "abc"
'abcdd'.chomp('d') # => "abcd"

Like String#chop, but modifies self in place; returns nil if self is empty, self otherwise.

Related: String#chomp!.

Search took: 4ms  ·  Total Results: 1294