Scroll::HumanKey
Inherits Comparable < Struct < Value < Object
A --sort comparison key with a defined total order over numeric and
non-numeric lines. Lexical keys are represented as non-numeric keys (raw
string comparison), so a single concrete type covers both --sort and
--human. Under --human, non-numeric lines sort before numeric ones
(ascending), lexically among themselves; numeric lines sort by value.
Constants
Base for byte-suffix magnitudes (GNU sort -h uses 1024).
Unit letter (lowercased) => exponent applied to BASE.
A leading - is a sign only at a boundary; (?<![\w.]) keeps an embedded
- (as in a token like a-5k) a separator, so the digits parse positive
while a standalone -5 / -1.5 still parses negative.
Byte-suffix value: non-negative magnitude + unit letter (+ optional B).
The (?<!-) lookbehind enforces that byte values are never negative. The
trailing delimiter is a lookahead so it is not consumed into the match.
Constructors
Instance methods
The comparison operator. Returns 0 if the two objects are equal,
a negative number if this object is considered less than other,
a positive number if this object is considered greater than other,
or nil if the two objects are not comparable.
Subclasses define this method to provide class-specific ordering.
The comparison operator is usually used to sort values:
# Sort in a descending way:
[3, 1, 2].sort { |x, y| y <=> x } # => [3, 2, 1]
# Sort in an ascending way:
[3, 1, 2].sort { |x, y| x <=> y } # => [1, 2, 3]