Builds a methods for level meth
.
Clean up messages so they’re nice and pretty.
An Integer object represents an integer value.
You can create an Integer object explicitly with:
An integer literal.
You can convert certain objects to Integers with:
Method Integer
.
An attempt to add a singleton method to an instance of this class causes an exception to be raised.
First, what’s elsewhere. Class Integer:
Inherits from class Numeric.
Here, class Integer provides methods for:
allbits?
: Returns whether all bits in self
are set.
anybits?
: Returns whether any bits in self
are set.
nobits?
: Returns whether no bits in self
are set.
<
: 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 ===
): 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.
::sqrt
: Returns the integer square root of the given value.
::try_convert
: Returns the given value converted to an Integer.
&
: Returns the bitwise AND of self
and 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.
<<
: Returns the value of self
after a leftward bit-shift.
>>
: Returns the value of self
after a rightward bit-shift.
[]
: Returns a slice of bits from self
.
^
: Returns the bitwise EXCLUSIVE OR of self
and the given value.
ceil
: Returns the smallest number greater than or equal to self
.
chr
: Returns a 1-character string containing the character represented by the value of self
.
digits
: Returns an array of integers representing the base-radix digits of self
.
div
: Returns the integer result of dividing self
by the given value.
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
.
pow
: Returns the modular exponentiation of self
.
pred
: Returns the integer predecessor of self
.
remainder
: Returns the remainder after dividing self
by the given value.
round
: Returns self
rounded to the nearest value with the given precision.
succ
(aliased as next
): Returns the integer successor of self
.
to_s
(aliased as inspect
): Returns a string containing the place-value representation of self
in the given radix.
truncate
: Returns self
truncated to the given precision.
|
: Returns the bitwise OR of self
and the given value.
Raised when an invalid operation is attempted on a Fiber
, in particular when attempting to call/resume a dead fiber, attempting to yield from the root fiber, or calling a fiber across threads.
fiber = Fiber.new{} fiber.resume #=> nil fiber.resume #=> FiberError: dead fiber called
Raised when a given numerical value is out of range.
[1, 2, 3].drop(1 << 100)
raises the exception:
RangeError: bignum too big to convert into `long'
Raised when a file required (a Ruby script, extension library, …) fails to load.
require 'this/file/does/not/exist'
raises the exception:
LoadError: no such file to load -- this/file/does/not/exist
EncodingError
is the base class for encoding errors.
TCPServer
represents a TCP/IP server socket.
A simple TCP server may look like:
require 'socket' server = TCPServer.new 2000 # Server bind to port 2000 loop do client = server.accept # Wait for a client to connect client.puts "Hello !" client.puts "Time is #{Time.now}" client.close end
A more usable server (serving multiple clients):
require 'socket' server = TCPServer.new 2000 loop do Thread.start(server.accept) do |client| client.puts "Hello !" client.puts "Time is #{Time.now}" client.close end end