📁 File Manager Pro
v10.0.3 | PHP: 8.1.34
Server: Apache
2026-06-22 10:05:41
📂
/ (Root)
/
opt
/
alt
/
ruby30
/
share
/
ri
/
system
/
Numeric
📍 /opt/alt/ruby30/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;0: @fileI"numeric.c;T:0@omit_headings_from_table_of_contents_below0; 0;0[ [ [[I"Comparable;To;;[ ; @\;0I"numeric.c;T[[I" class;T[[:public[ [:protected[ [:private[ [I" instance;T[[;[ [;[ [;[3[I"%;T@d[I"+@;T@d[I"-@;T@d[I"<=>;T@d[I"abs;T@d[I" abs2;TI"complex.c;T[I" angle;T@[I"arg;T@[I" ceil;T@d[I" clone;T@d[I"coerce;T@d[I" conj;T@[I"conjugate;T@[I"denominator;TI"rational.c;T[I"div;T@d[I"divmod;T@d[I"dup;T@d[I" eql?;T@d[I" fdiv;T@d[I"finite?;T@d[I" floor;T@d[I"i;T@d[I" imag;T@[I"imaginary;T@[I"infinite?;T@d[I" integer?;T@d[I"magnitude;T@d[I"modulo;T@d[I"negative?;T@d[I" nonzero?;T@d[I"numerator;T@�[I" phase;T@[I" polar;T@[I"positive?;T@d[I"quo;T@�[I" real;T@[I" real?;T@d[I" rect;T@[I"rectangular;T@[I"remainder;T@d[I" round;T@d[I" step;T@d[I" to_c;T@[I"to_int;T@d[I" truncate;T@d[I" zero?;T@d[ [U:RDoc::Context::Section[i 0o;;[ ; 0;0[I"complex.c;TI"numeric.c;TI"rational.c;T@\cRDoc::TopLevel
💾 Save Changes
❌ Cancel