Class

Integer

Extends:

Provides support for converting integers to Strings, and back again. The strings are structured so that lexicographic sorting order is preserved.

That is, if integer1 is less than integer2 for any two integers integer1 and integer2, then integer1.to_s_lex is lexicographically less than integer2.to_s_lex. (Similarly for "greater than" and "equals".)

This class handles numbers between - 10 ** 10,000 and 10 ** 10,000 which should cover all practical numbers. If you need bigger numbers, increase Integer::LEN_STR_SIZE.

Constants
LEN_STR_SIZE LEN_SIZE of 4 should handle most numbers that can practically be held in memory.
LEN_STR_TEMPLATE
NEG_LEN_MASK
Public Methods
to_s_lex Convert the number to a lexicographically sortable string. This string will use printable characters only but will not be human readable.
to_s_pad Convert the number to a lexicographically sortable string by padding with 0s. You should make sure that you set the width to a number large enough to accommodate all possible values. Also note that this method will not work with negative numbers. That is negative numbers will sort in the opposite direction as positive numbers. If you have very large numbers or a mix of positive and negative numbers you should use the Integer#to_s_lex method
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.