D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
opt
/
alt
/
ruby18
/
share
/
ri
/
1.8
/
system
/
Comparable
/
Filename :
cdesc-Comparable.yaml
back
Copy
--- !ruby/object:RI::ClassDescription attributes: [] class_methods: [] comment: - !ruby/struct:SM::Flow::P body: The <tt>Comparable</tt> mixin is used by classes whose objects may be ordered. The class must define the <tt><=></tt> operator, which compares the receiver against another object, returning -1, 0, or +1 depending on whether the receiver is less than, equal to, or greater than the other object. <tt>Comparable</tt> uses <tt><=></tt> to implement the conventional comparison operators (<tt><</tt>, <tt><=</tt>, <tt>==</tt>, <tt>>=</tt>, and <tt>></tt>) and the method <tt>between?</tt>. - !ruby/struct:SM::Flow::VERB body: " class SizeMatters\n include Comparable\n attr :str\n def <=>(anOther)\n str.size <=> anOther.str.size\n end\n def initialize(str)\n @str = str\n end\n def inspect\n @str\n end\n end\n\n s1 = SizeMatters.new("Z")\n s2 = SizeMatters.new("YY")\n s3 = SizeMatters.new("XXX")\n s4 = SizeMatters.new("WWWW")\n s5 = SizeMatters.new("VVVVV")\n\n s1 < s2 #=> true\n s4.between?(s1, s3) #=> false\n s4.between?(s3, s5) #=> true\n [ s3, s2, s5, s4, s1 ].sort #=> [Z, YY, XXX, WWWW, VVVVV]\n" constants: [] full_name: Comparable includes: [] instance_methods: - !ruby/object:RI::MethodSummary name: < - !ruby/object:RI::MethodSummary name: <= - !ruby/object:RI::MethodSummary name: == - !ruby/object:RI::MethodSummary name: ">" - !ruby/object:RI::MethodSummary name: ">=" - !ruby/object:RI::MethodSummary name: between? name: Comparable superclass: