Represents a block parameter to a method, block, or lambda definition.
def a(&b)
^^
end
Represents a block’s parameters declaration.
-> (a, b = 1; local) { }
^^^^^^^^^^^^^^^^^
foo do |a, b = 1; local|
^^^^^^^^^^^^^^^^^
end
Represents the use of the ‘&&=` operator for assignment to a constant path.
Parent::Child &&= value ^^^^^^^^^^^^^^^^^^^^^^^
Represents the use of the ‘||=` operator for assignment to a constant path.
Parent::Child ||= value ^^^^^^^^^^^^^^^^^^^^^^^
Represents writing to a constant path in a context that doesn’t have an explicit value.
Foo::Foo, Bar::Bar = baz ^^^^^^^^ ^^^^^^^^
Represents writing to a constant path.
::Foo = 1 ^^^^^^^^^ Foo::Bar = 1 ^^^^^^^^^^^^ ::Foo::Bar = 1 ^^^^^^^^^^^^^^
Represents the use of the forwarding parameter in a method, block, or lambda declaration.
def foo(...)
^^^
end
Represents a keyword rest parameter to a method, block, or lambda definition.
def a(**b)
^^^
end
Represents the use of ‘**nil` inside method arguments.
def a(**nil)
^^^^^
end
Represents an implicit set of parameters through the use of numbered parameters within a block or lambda.
-> { _1 + _2 }
^^^^^^^^^^^^^^
Represents the list of parameters on a method, block, or lambda definition.
def a(b, c, d)
^^^^^^^
end
Represents a required keyword parameter to a method, block, or lambda definition.
def a(b: )
^^
end
Represents a required parameter to a method, block, or lambda definition.
def a(b)
^
end
Represents a rest parameter to a method, block, or lambda definition.
def a(*b)
^^
end
Raised by Gem::WebauthnListener when an error occurs during security device verification.
Represents a gem of name name at version of platform. These wrap the data returned from the indexes.
Gem::PathSupport facilitates the GEM_HOME and GEM_PATH environment settings to the rest of RubyGems.
Numeric is the class from which all higher-level numeric classes should inherit.
Numeric allows instantiation of heap-allocated objects. Other core numeric classes such as Integer are implemented as immediates, which means that each Integer is a single immutable object which is always passed by value.
a = 1 1.object_id == a.object_id #=> true
There can only ever be one instance of the integer 1, for example. Ruby ensures this by preventing instantiation. If duplication is attempted, the same instance is returned.
Integer.new(1) #=> NoMethodError: undefined method `new' for Integer:Class 1.dup #=> 1 1.object_id == 1.dup.object_id #=> true
For this reason, Numeric should be used when defining other numeric classes.
Classes which inherit from Numeric must implement coerce, which returns a two-member Array containing an object that has been coerced into an instance of the new class and self (see coerce).
Inheriting classes should also implement arithmetic operator methods (+, -, * and /) and the <=> operator (see Comparable). These methods may rely on coerce to ensure interoperability with instances of other numeric classes.
class Tally < Numeric def initialize(string) @string = string end def to_s @string end def to_i @string.size end def coerce(other) [self.class.new('|' * other.to_i), self] end def <=>(other) to_i <=> other.to_i end def +(other) self.class.new('|' * (to_i + other.to_i)) end def -(other) self.class.new('|' * (to_i - other.to_i)) end def *(other) self.class.new('|' * (to_i * other.to_i)) end def /(other) self.class.new('|' * (to_i / other.to_i)) end end tally = Tally.new('||') puts tally * 2 #=> "||||" puts tally > 1 #=> true
First, what’s elsewhere. Class Numeric:
Inherits from class Object.
Includes module Comparable.
Here, class Numeric provides methods for:
finite?: Returns true unless self is infinite or not a number.
infinite?: Returns -1, nil or +1, depending on whether self is -Infinity<tt>, finite, or <tt>+Infinity.
integer?: Returns whether self is an integer.
negative?: Returns whether self is negative.
nonzero?: Returns whether self is not zero.
positive?: Returns whether self is positive.
real?: Returns whether self is a real value.
zero?: Returns whether self is zero.
<=>: Returns:
-1 if self is less than the given value.
0 if self is equal to the given value.
1 if self is greater than the given value.
nil if self and the given value are not comparable.
eql?: Returns whether self and the given value have the same value and type.
% (aliased as modulo): Returns the remainder of self divided by the given value.
-@: Returns the value of self, negated.
abs (aliased as magnitude): Returns the absolute value of self.
abs2: Returns the square of self.
angle (aliased as arg and phase): Returns 0 if self is positive, Math::PI otherwise.
ceil: Returns the smallest number greater than or equal to self, to a given precision.
coerce: Returns array [coerced_self, coerced_other] for the given other value.
conj (aliased as conjugate): Returns the complex conjugate of self.
denominator: Returns the denominator (always positive) of the Rational representation of self.
div: Returns the value of self divided by the given value and converted to an integer.
divmod: Returns array [quotient, modulus] resulting from dividing self the given divisor.
fdiv: Returns the Float result of dividing self by the given divisor.
floor: Returns the largest number less than or equal to self, to a given precision.
i: Returns the Complex object Complex(0, self). the given value.
imaginary (aliased as imag): Returns the imaginary part of the self.
numerator: Returns the numerator of the Rational representation of self; has the same sign as self.
polar: Returns the array [self.abs, self.arg].
quo: Returns the value of self divided by the given value.
real: Returns the real part of self.
rect (aliased as rectangular): Returns the array [self, 0].
remainder: Returns self-arg*(self/arg).truncate for the given arg.
round: Returns the value of self rounded to the nearest value for the given a precision.
to_int: Returns the Integer representation of self, truncating if necessary.
truncate: Returns self truncated (toward zero) to a given precision.
A Float object represents a sometimes-inexact real number using the native architecture’s double-precision floating point representation.
Floating point has a different arithmetic and is an inexact number. So you should know its esoteric system. See following:
You can create a Float object explicitly with:
A floating-point literal.
You can convert certain objects to Floats with:
Method Float.
First, what’s elsewhere. Class Float:
Inherits from class Numeric.
Here, class Float provides methods for:
finite?: Returns whether self is finite.
hash: Returns the integer hash code for self.
infinite?: Returns whether self is infinite.
nan?: Returns whether self is a NaN (not-a-number).
<: Returns whether self is less than the given value.
<=: Returns whether self is less than or equal to the given value.
<=>: Returns a number indicating whether self is less than, equal to, or greater than the given value.
== (aliased as === and eql?): Returns whether self is equal to the given value.
>: Returns whether self is greater than the given value.
>=: Returns whether self is greater than or equal to the given value.
*: Returns the product of self and the given value.
**: Returns the value of self raised to the power of the given value.
+: Returns the sum of self and the given value.
-: Returns the difference of self and the given value.
/: Returns the quotient of self and the given value.
ceil: Returns the smallest number greater than or equal to self.
coerce: Returns a 2-element array containing the given value converted to a Float and self
divmod: Returns a 2-element array containing the quotient and remainder results of dividing self by the given value.
fdiv: Returns the Float result of dividing self by the given value.
floor: Returns the greatest number smaller than or equal to self.
next_float: Returns the next-larger representable Float.
prev_float: Returns the next-smaller representable Float.
quo: Returns the quotient from dividing self by the given value.
round: Returns self rounded to the nearest value, to a given precision.
to_i (aliased as to_int): Returns self truncated to an Integer.
to_s (aliased as inspect): Returns a string containing the place-value representation of self in the given radix.
truncate: Returns self truncated to a given precision.
Continuation objects are generated by Kernel#callcc, after having +require+d continuation. They hold a return address and execution context, allowing a nonlocal return to the end of the callcc block from anywhere within a program. Continuations are somewhat analogous to a structured version of C’s setjmp/longjmp (although they contain more state, so you might consider them closer to threads).
For instance:
require "continuation" arr = [ "Freddie", "Herbie", "Ron", "Max", "Ringo" ] callcc{|cc| $cc = cc} puts(message = arr.shift) $cc.call unless message =~ /Max/
produces:
Freddie Herbie Ron Max
Also you can call callcc in other methods:
require "continuation" def g arr = [ "Freddie", "Herbie", "Ron", "Max", "Ringo" ] cc = callcc { |cc| cc } puts arr.shift return cc, arr.size end def f c, size = g c.call(c) if size > 1 end f
This (somewhat contrived) example allows the inner loop to abandon processing early:
require "continuation" callcc {|cont| for i in 0..4 print "#{i}: " for j in i*5...(i+1)*5 cont.call() if j == 17 printf "%3d", j end end } puts
produces:
0: 0 1 2 3 4 1: 5 6 7 8 9 2: 10 11 12 13 14 3: 15 16
Raised to stop the iteration, in particular by Enumerator#next. It is rescued by Kernel#loop.
loop do puts "Hello" raise StopIteration puts "World" end puts "Done!"
produces:
Hello Done!
Raised by exit to initiate the termination of the script.