D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
Comparable
/
Filename :
cdesc-Comparable.ri
back
Copy
U:RDoc::NormalModule[iI"Comparable:ET@0o:RDoc::Markup::Document:@parts[o;;[ o:RDoc::Markup::Paragraph;[I"BThe Comparable mixin is used by classes whose objects may be ;TI"Cordered. The class must define the <code><=></code> operator, ;TI"Ewhich compares the receiver against another object, returning a ;TI"Jvalue less than 0, returning 0, or returning a value greater than 0, ;TI"?depending on whether the receiver is less than, equal to, ;TI"Bor greater than the other object. If the other object is not ;TI"Hcomparable then the <code><=></code> operator should return +nil+. ;TI"DComparable uses <code><=></code> to implement the conventional ;TI"<comparison operators (<code><</code>, <code><=</code>, ;TI"C<code>==</code>, <code>>=</code>, and <code>></code>) and the ;TI""method <code>between?</code>.;To:RDoc::Markup::BlankLine o:RDoc::Markup::Verbatim;[ I"class StringSorter ;TI" include Comparable ;TI" ;TI" attr :str ;TI" def <=>(other) ;TI"% str.size <=> other.str.size ;TI" end ;TI" ;TI" def initialize(str) ;TI" @str = str ;TI" end ;TI" ;TI" def inspect ;TI" @str ;TI" end ;TI" end ;TI" ;TI" s1 = StringSorter.new("Z") ;TI"!s2 = StringSorter.new("YY") ;TI""s3 = StringSorter.new("XXX") ;TI"#s4 = StringSorter.new("WWWW") ;TI"$s5 = StringSorter.new("VVVVV") ;TI" ;TI",s1 < s2 #=> true ;TI"-s4.between?(s1, s3) #=> false ;TI",s4.between?(s3, s5) #=> true ;TI"A[ s3, s2, s5, s4, s1 ].sort #=> [Z, YY, XXX, WWWW, VVVVV] ;T:@format0S:RDoc::Markup::Heading: leveli: textI"What's Here;T@o; ;[I"W\Module \Comparable provides these methods, all of which use method <tt>#<=></tt>:;T@o:RDoc::Markup::List: @type:BULLET:@items[o:RDoc::Markup::ListItem:@label0;[o; ;[I">#<: Returns whether +self+ is less than the given object.;To;;0;[o; ;[I"K#<=: Returns whether +self+ is less than or equal to the given object.;To;;0;[o; ;[I">#==: Returns whether +self+ is equal to the given object.;To;;0;[o; ;[I"A#>: Returns whether +self+ is greater than the given object.;To;;0;[o; ;[I"N#>=: Returns whether +self+ is greater than or equal to the given object.;To;;0;[o; ;[I"F#between?: Returns +true+ if +self+ is between two given objects.;To;;0;[o; ;[I"V#clamp: For given objects +min+ and +max+, or range <tt>(min..max)</tt>, returns:;T@o;;;;[o;;0;[o; ;[I"*+min+ if <tt>(self <=> min) < 0</tt>.;To;;0;[o; ;[I"*+max+ if <tt>(self <=> max) > 0</tt>.;To;;0;[o; ;[I"+self+ otherwise.;T: @fileI" compar.c;T:0@omit_headings_from_table_of_contents_below0;0;0[ [ [ [[I" class;T[[:public[ [:protected[ [:private[ [I" instance;T[[;[[I"<;TI" compar.c;T[I"<=;T@�[I"==;T@�[I">;T@�[I">=;T@�[I" between?;T@�[I" clamp;T@�[;[ [;[ [ [U:RDoc::Context::Section[i 0o;;[ ;0;0[@r@rcRDoc::TopLevel