Method: External::Io#sort_compare
- Defined in:
- lib/external/io.rb
#sort_compare(another, blksize = default_blksize) ⇒ Object
Sort compare (ie <=>) with another IO, behaving like a comparison between the full string contents of self and another. This obviously can be a long operation if it requires the full read of two large IO objects.
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/external/io.rb', line 129 def sort_compare(another, blksize=default_blksize) # equal in comparison if the ios are equal return 0 if quick_compare(another) self.flush self.reset_length another.flush another.reset_length if another.length > self.length return -1 elsif self.length < another.length return 1 else self.pos = 0 another.pos = 0 sa = sb = nil while sa == sb sa = self.read(blksize) sb = another.read(blksize) break if sa.nil? || sb.nil? end sa.to_s <=> sb.to_s end end |