returns “type/subtype” which is MIME Content-Type. It is downcased for canonicalization. Content-Type parameters are stripped.
Message to promote available RubyGems update with related gem update command.
Format and print out counters as a String
. This returns a non-empty content only when --yjit-stats
is enabled.
Returns a new array containing the elements of self
in reverse order:
[0, 1, 2].reverse # => [2, 1, 0]
Related: see Methods for Combining.
Reverses the order of the elements of self
; returns self
:
a = [0, 1, 2] a.reverse! # => [2, 1, 0] a # => [2, 1, 0]
Related: see Methods for Assigning.
Returns the remainder after dividing self
by other
.
Examples:
11.remainder(4) # => 3 11.remainder(-4) # => 3 -11.remainder(4) # => -3 -11.remainder(-4) # => -3 12.remainder(4) # => 0 12.remainder(-4) # => 0 -12.remainder(4) # => 0 -12.remainder(-4) # => 0 13.remainder(4.0) # => 1.0 13.remainder(Rational(4, 1)) # => (1/1)
Returns the remainder after dividing self
by other
.
Of the Core and Standard Library classes, only Float
and Rational
use this implementation.
Examples:
11.0.remainder(4) # => 3.0 11.0.remainder(-4) # => 3.0 -11.0.remainder(4) # => -3.0 -11.0.remainder(-4) # => -3.0 12.0.remainder(4) # => 0.0 12.0.remainder(-4) # => 0.0 -12.0.remainder(4) # => -0.0 -12.0.remainder(-4) # => -0.0 13.0.remainder(4.0) # => 1.0 13.0.remainder(Rational(4, 1)) # => 1.0 Rational(13, 1).remainder(4) # => (1/1) Rational(13, 1).remainder(-4) # => (1/1) Rational(-13, 1).remainder(4) # => (-1/1) Rational(-13, 1).remainder(-4) # => (-1/1)
Returns a new string with the characters from self
in reverse order.
'stressed'.reverse # => "desserts"
Returns self
with its characters reversed:
s = 'stressed' s.reverse! # => "desserts" s # => "desserts"
Return the receiver associated with this KeyError
exception.
Return the receiver associated with this NameError
exception.
Return the receiver associated with this FrozenError
exception.
Returns an array of Refinement
defined within the receiver.
module A refine Integer do end refine String do end end p A.refinements
produces:
[#<refinement:Integer@A>, #<refinement:String@A>]
Returns true
if range
overlaps with self
, false
otherwise:
(0..2).overlap?(1..3) #=> true (0..2).overlap?(3..4) #=> false (0..).overlap?(..0) #=> true
With non-range argument, raises TypeError
.
(1..3).overlap?(1) # TypeError
Returns false
if an internal call to #<=>
returns nil
; that is, the operands are not comparable.
(1..3).overlap?('a'..'d') # => false
Returns false
if self
or range
is empty. “Empty range” means that its begin value is larger than, or equal for an exclusive range, its end value.
(4..1).overlap?(2..3) # => false (4..1).overlap?(..3) # => false (4..1).overlap?(2..) # => false (2...2).overlap?(1..2) # => false (1..4).overlap?(3..2) # => false (..4).overlap?(3..2) # => false (1..).overlap?(3..2) # => false (1..2).overlap?(2...2) # => false
Returns false
if the begin value one of self
and range
is larger than, or equal if the other is an exclusive range, the end value of the other:
(4..5).overlap?(2..3) # => false (4..5).overlap?(2...4) # => false (1..2).overlap?(3..4) # => false (1...3).overlap?(3..4) # => false
Returns false
if the end value one of self
and range
is larger than, or equal for an exclusive range, the end value of the other:
(4..5).overlap?(2..3) # => false (4..5).overlap?(2...4) # => false (1..2).overlap?(3..4) # => false (1...3).overlap?(3..4) # => false
Note that the method wouldn’t make any assumptions about the beginless range being actually empty, even if its upper bound is the minimum possible value of its type, so all this would return true
:
(...-Float::INFINITY).overlap?(...-Float::INFINITY) # => true (..."").overlap?(..."") # => true (...[]).overlap?(...[]) # => true
Even if those ranges are effectively empty (no number can be smaller than -Float::INFINITY
), they are still considered overlapping with themselves.
Related: Range#cover?
.
The opposite of Pathname#absolute?
It returns false
if the pathname begins with a slash.
p = Pathname.new('/im/sure') p.relative? #=> false p = Pathname.new('not/so/sure') p.relative? #=> true
Returns a string for DNS reverse lookup. It returns a string in RFC3172 form for an IPv6 address.
Returns the bound receiver of the binding object.
Returns the bound receiver of the method object.
(1..3).method(:map).receiver # => 1..3
Receive a message from the incoming port of the current ractor (which was sent there by send
from another ractor).
r = Ractor.new do v1 = Ractor.receive puts "Received: #{v1}" end r.send('message1') r.take # Here will be printed: "Received: message1"
Alternatively, the private instance method receive
may be used:
r = Ractor.new do v1 = receive puts "Received: #{v1}" end r.send('message1') r.take # This prints: "Received: message1"
The method blocks if the queue is empty.
r = Ractor.new do puts "Before first receive" v1 = Ractor.receive puts "Received: #{v1}" v2 = Ractor.receive puts "Received: #{v2}" end wait puts "Still not received" r.send('message1') wait puts "Still received only one" r.send('message2') r.take
Output:
Before first receive Still not received Received: message1 Still received only one Received: message2
If close_incoming
was called on the ractor, the method raises Ractor::ClosedError
if there are no more messages in the incoming queue:
Ractor.new do close_incoming receive end wait # in `receive': The incoming port is already closed => #<Ractor:#2 test.rb:1 running> (Ractor::ClosedError)