📁 File Manager Pro
v10.0.3 | PHP: 8.1.34
Server: Apache
2026-06-22 05:45:45
📂
/ (Root)
/
opt
/
alt
/
ruby31
/
share
/
ri
/
system
/
Numeric
📍 /opt/alt/ruby31/share/ri/system/Numeric
🔄 Refresh
✏️
Editing: cdesc-Numeric.ri
Read Only
U:RDoc::NormalClass[iI"Numeric:ET@I"Object;To:RDoc::Markup::Document:@parts[o;;[(o:RDoc::Markup::Paragraph;[I"UNumeric is the class from which all higher-level numeric classes should inherit.;To:RDoc::Markup::BlankLine o; ;[I"`Numeric allows instantiation of heap-allocated objects. Other core numeric classes such as ;TI"`Integer are implemented as immediates, which means that each Integer is a single immutable ;TI",object which is always passed by value.;T@o:RDoc::Markup::Verbatim;[I"a = 1 ;TI"+1.object_id == a.object_id #=> true ;T:@format0o; ;[I"\There can only ever be one instance of the integer +1+, for example. Ruby ensures this ;TI"]by preventing instantiation. If duplication is attempted, the same instance is returned.;T@o;;[I"bInteger.new(1) #=> NoMethodError: undefined method `new' for Integer:Class ;TI",1.dup #=> 1 ;TI"/1.object_id == 1.dup.object_id #=> true ;T;0o; ;[I"QFor this reason, Numeric should be used when defining other numeric classes.;T@o; ;[I"\Classes which inherit from Numeric must implement +coerce+, which returns a two-member ;TI"XArray containing an object that has been coerced into an instance of the new class ;TI"and +self+ (see #coerce).;T@o; ;[ I"[Inheriting classes should also implement arithmetic operator methods (<code>+</code>, ;TI"_<code>-</code>, <code>*</code> and <code>/</code>) and the <code><=></code> operator (see ;TI"UComparable). These methods may rely on +coerce+ to ensure interoperability with ;TI"(instances of other numeric classes.;T@o;;[.I"class Tally < Numeric ;TI" def initialize(string) ;TI" @string = string ;TI" end ;TI" ;TI" def to_s ;TI" @string ;TI" end ;TI" ;TI" def to_i ;TI" @string.size ;TI" end ;TI" ;TI" def coerce(other) ;TI"2 [self.class.new('|' * other.to_i), self] ;TI" end ;TI" ;TI" def <=>(other) ;TI" to_i <=> other.to_i ;TI" end ;TI" ;TI" def +(other) ;TI"3 self.class.new('|' * (to_i + other.to_i)) ;TI" end ;TI" ;TI" def -(other) ;TI"3 self.class.new('|' * (to_i - other.to_i)) ;TI" end ;TI" ;TI" def *(other) ;TI"3 self.class.new('|' * (to_i * other.to_i)) ;TI" end ;TI" ;TI" def /(other) ;TI"3 self.class.new('|' * (to_i / other.to_i)) ;TI" end ;TI" end ;TI" ;TI"tally = Tally.new('||') ;TI"*puts tally * 2 #=> "||||" ;TI"(puts tally > 1 #=> true ;T;0S:RDoc::Markup::Heading: leveli: textI"What's Here;T@o; ;[I".First, what's elsewhere. \Class \Numeric:;T@o:RDoc::Markup::List: @type:BULLET:@items[o:RDoc::Markup::ListItem:@label0;[o; ;[I"PInherits from {class Object}[Object.html#class-Object-label-What-27s+Here].;To;;0;[o; ;[I"YIncludes {module Comparable}[Comparable.html#module-Comparable-label-What-27s+Here].;T@o; ;[I"/Here, class \Numeric provides methods for:;T@o;;;;[ o;;0;[o; ;[I".{Querying}[#class-Numeric-label-Querying];To;;0;[o; ;[I"0{Comparing}[#class-Numeric-label-Comparing];To;;0;[o; ;[I"2{Converting}[#class-Numeric-label-Converting];To;;0;[o; ;[I"({Other}[#class-Numeric-label-Other];T@S; ;i;I" Querying;T@o;;;;[ o;;0;[o;;: NOTE;[o;;[I" #finite?;T;[o; ;[I"<Returns true unless +self+ is infinite or not a number.;To;;0;[o;;;;[o;;[I"#infinite?;T;[o; ;[I":Returns -1, +nil+ or +1, depending on whether +self+ ;TI"9is <tt>-Infinity<tt>, finite, or <tt>+Infinity</tt>.;To;;0;[o;;;;[o;;[I"#integer?;T;[o; ;[I"*Returns whether +self+ is an integer.;To;;0;[o;;;;[o;;[I"#negative?;T;[o; ;[I"(Returns whether +self+ is negative.;To;;0;[o;;;;[o;;[I"#nonzero?;T;[o; ;[I"(Returns whether +self+ is not zero.;To;;0;[o;;;;[o;;[I"#positive?;T;[o; ;[I"(Returns whether +self+ is positive.;To;;0;[o;;;;[o;;[I"#real?;T;[o; ;[I",Returns whether +self+ is a real value.;To;;0;[o;;;;[o;;[I"#zero?;T;[o; ;[I"$Returns whether +self+ is zero.;T@S; ;i;I"Comparing;T@o;;;;[o;;0;[o;;;;[o;;[I"{<=>}[#method-i-3C-3D-3E];T;[o; ;[I" Returns:;To;;;;[ o;;0;[o; ;[I"0-1 if +self+ is less than the given value.;To;;0;[o; ;[I"-0 if +self+ is equal to the given value.;To;;0;[o; ;[I"11 if +self+ is greater than the given value.;To;;0;[o; ;[I"<+nil+ if +self+ and the given value are not comparable.;To;;0;[o;;;;[o;;[I" #eql?;T;[o; ;[I"MReturns whether +self+ and the given value have the same value and type.;T@S; ;i;I"Converting;T@o;;;;[o;;0;[o;;;;[o;;[I"#% (aliased as #modulo);T;[o; ;[I"@Returns the remainder of +self+ divided by the given value.;To;;0;[o;;;;[o;;[I"#-@;T;[o; ;[I"*Returns the value of +self+, negated.;To;;0;[o;;;;[o;;[I"!#abs (aliased as #magnitude);T;[o; ;[I"*Returns the absolute value of +self+.;To;;0;[o;;;;[o;;[I" #abs2;T;[o; ;[I""Returns the square of +self+.;To;;0;[o;;;;[o;;[I"(#angle (aliased as #arg and #phase);T;[o; ;[I"&Returns 0 if +self+ is positive, ;TI"Math::PI otherwise.;To;;0;[o;;;;[o;;[I" #ceil;T;[o; ;[I"BReturns the smallest number greater than or equal to +self+, ;TI"to a given precision.;To;;0;[o;;;;[o;;[I"#coerce;T;[o; ;[I":Returns array <tt>[coerced_self, coerced_other]</tt> ;TI"for the given other value.;To;;0;[o;;;;[o;;[I""#conj (aliased as #conjugate);T;[o; ;[I"-Returns the complex conjugate of +self+.;To;;0;[o;;;;[o;;[I"#denominator;T;[o; ;[I"/Returns the denominator (always positive) ;TI".of the Rational representation of +self+.;To;;0;[o;;;;[o;;[I" #div;T;[o; ;[I"<Returns the value of +self+ divided by the given value ;TI"!and converted to an integer.;To;;0;[o;;;;[o;;[I"#divmod;T;[o; ;[I":Returns array <tt>[quotient, modulus]</tt> resulting ;TI",from dividing +self+ the given divisor.;To;;0;[o;;;;[o;;[I" #fdiv;T;[o; ;[I"FReturns the Float result of dividing +self+ by the given divisor.;To;;0;[o;;;;[o;;[I"#floor;T;[o; ;[I">Returns the largest number less than or equal to +self+, ;TI"to a given precision.;To;;0;[o;;;;[o;;[I"#i;T;[o; ;[I";Returns the Complex object <tt>Complex(0, self)</tt>. ;TI"the given value.;To;;0;[o;;;;[o;;[I""#imaginary (aliased as #imag);T;[o; ;[I".Returns the imaginary part of the +self+.;To;;0;[o;;;;[o;;[I"#numerator;T;[o; ;[I"EReturns the numerator of the Rational representation of +self+; ;TI"!has the same sign as +self+.;To;;0;[o;;;;[o;;[I"#polar;T;[o; ;[I"5Returns the array <tt>[self.abs, self.arg]</tt>.;To;;0;[o;;;;[o;;[I" #quo;T;[o; ;[I"<Returns the value of +self+ divided by the given value.;To;;0;[o;;;;[o;;[I" #real;T;[o; ;[I"%Returns the real part of +self+.;To;;0;[o;;;;[o;;[I"$#rect (aliased as #rectangular);T;[o; ;[I"*Returns the array <tt>[self, 0]</tt>.;To;;0;[o;;;;[o;;[I"#remainder;T;[o; ;[I"GReturns <tt>self-arg*(self/arg).truncate</tt> for the given +arg+.;To;;0;[o;;;;[o;;[I"#round;T;[o; ;[I">Returns the value of +self+ rounded to the nearest value ;TI"for the given a precision.;To;;0;[o;;;;[o;;[I" #to_c;T;[o; ;[I"2Returns the Complex representation of +self+.;To;;0;[o;;;;[o;;[I"#to_int;T;[o; ;[I"KReturns the Integer representation of +self+, truncating if necessary.;To;;0;[o;;;;[o;;[I"#truncate;T;[o; ;[I"AReturns +self+ truncated (toward zero) to a given precision.;T@S; ;i;I" Other;T@o;;;;[o;;0;[o;;;;[o;;[I"#clone;T;[o; ;[I"-Returns +self+; does not allow freezing.;To;;0;[o;;;;[o;;[I"#dup (aliased as #+@);T;[o; ;[I"Returns +self+.;To;;0;[o;;;;[o;;[I" #step;T;[o; ;[I"DInvokes the given block with the sequence of specified numbers.;T: @fileI"numeric.c;T:0@omit_headings_from_table_of_contents_below0o;;[ ;I"numeric.rb;T;0;0;0[ [ [[I"Comparable;To;;[ ;@T;0I"numeric.c;T[[I" class;T[[:public[ [:protected[ [:private[ [I" instance;T[[;[ [;[ [;[3[I"%;T@_[I"+@;T@_[I"-@;T@_[I"<=>;T@_[I"abs;T@_[I" abs2;TI"complex.c;T[I" angle;T@[I"arg;T@[I" ceil;T@_[I" clone;T@_[I"coerce;T@_[I" conj;T@[I"conjugate;T@[I"denominator;TI"rational.c;T[I"div;T@_[I"divmod;T@_[I"dup;T@_[I" eql?;T@_[I" fdiv;T@_[I"finite?;TI"numeric.rb;T[I" floor;T@_[I"i;T@_[I" imag;T@[I"imaginary;T@[I"infinite?;T@�[I" integer?;T@�[I"magnitude;T@_[I"modulo;T@_[I"negative?;T@_[I" nonzero?;T@_[I"numerator;T@�[I" phase;T@[I" polar;T@[I"positive?;T@_[I"quo;T@�[I" real;T@[I" real?;T@�[I" rect;T@[I"rectangular;T@[I"remainder;T@_[I" round;T@_[I" step;T@_[I" to_c;T@[I"to_int;T@_[I" truncate;T@_[I" zero?;T@_[ [U:RDoc::Context::Section[i 0o;;[ ;0;0[ I"complex.c;TI"numeric.c;TI"numeric.rb;TI"rational.c;T@WcRDoc::TopLevel
💾 Save Changes
❌ Cancel