A Fixnum
holds Integer
values that can be represented in a native machine word (minus 1 bit). If any operation on a Fixnum
exceeds this range, the value is automatically converted to a Bignum
.
Fixnum
objects have immediate value. This means that when they are assigned or passed as parameters, the actual object is passed, rather than a reference to that object. Assignment does not alias Fixnum
objects. There is effectively only one Fixnum
object instance for any given integer value, so, for example, you cannot add a singleton method to a Fixnum
.
fix | + |
aNumeric | Addition |
fix | - |
aNumeric | Subtraction |
fix | * |
aNumeric | Multiplication |
fix | / |
aNumeric | Division |
fix | % |
aNumeric | Modulo |
fix | ** |
aNumeric | Exponentiation |
Fixnum
.~ fix |
Invert bits | ||
fix | | |
aNumeric | Bitwise OR |
fix | & |
aNumeric | Bitwise AND |
fix | ^ |
aNumeric | Bitwise EXCLUSIVE OR |
fix | << |
aNumeric | Left-shift aNumeric bits |
fix | >> |
aNumeric | Right-shift aNumeric bits (with sign extension) |
Comparable
. a = 0b11001100101010
30.downto(0) do |n| print a[n] end
produces:
0000000000000000011001100101010
nil
nil
. id2name
has nothing to do with the Object.id
method. See also String#intern
and class Symbol
.
symbol = :@inst_var → :@inst_var
id = symbol.to_i → 9002
id.id2name → "@inst_var"
Fixnum
.
Float
.
Extracted from the book "Programming Ruby - The Pragmatic Programmer's Guide"
Copyright © 2001 by Addison Wesley Longman, Inc. This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at http://www.opencontent.org/openpub/).
Distribution of substantively modified versions of this document is prohibited without the explicit permission of the copyright holder.
Distribution of the work or derivative of the work in any standard (paper) book form is prohibited unless prior permission is obtained from the copyright holder.