Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Just a simple string-to-int algorithm
Ruby
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
spec
README.md

README.md

String-to-integer

This is a simple string to integer conversion algorithm, done without the assistance of ruby's builtin String#to_i. Obviously, this is just meant for learning and not for actual production use.

It is compatible with Ruby 1.8.7 and above.

Running the specs

gem install rspec -v=2.1.0
rspec spec/string_to_integer_spec.rb --format documentation

StringToInteger#to_integer
  converts '-100' to -100
  converts '-99' to -99
  converts '-98' to -98
  converts '-97' to -97
  converts '-96' to -96
  converts '-95' to -95
  converts '-94' to -94
  converts '-93' to -93
  converts '-92' to -92
  converts '-91' to -91
  converts '-90' to -90
  converts '-89' to -89
  converts '-88' to -88
  converts '-87' to -87
  converts '-86' to -86
  converts '-85' to -85
  converts '-84' to -84
  converts '-83' to -83
  converts '-82' to -82
  converts '-81' to -81
  converts '-80' to -80
  converts '-79' to -79
  converts '-78' to -78
  converts '-77' to -77
  converts '-76' to -76
  converts '-75' to -75
  converts '-74' to -74
  converts '-73' to -73
  converts '-72' to -72
  converts '-71' to -71
  converts '-70' to -70
  converts '-69' to -69
  converts '-68' to -68
  converts '-67' to -67
  converts '-66' to -66
  converts '-65' to -65
  converts '-64' to -64
  converts '-63' to -63
  converts '-62' to -62
  converts '-61' to -61
  converts '-60' to -60
  converts '-59' to -59
  converts '-58' to -58
  converts '-57' to -57
  converts '-56' to -56
  converts '-55' to -55
  converts '-54' to -54
  converts '-53' to -53
  converts '-52' to -52
  converts '-51' to -51
  converts '-50' to -50
  converts '-49' to -49
  converts '-48' to -48
  converts '-47' to -47
  converts '-46' to -46
  converts '-45' to -45
  converts '-44' to -44
  converts '-43' to -43
  converts '-42' to -42
  converts '-41' to -41
  converts '-40' to -40
  converts '-39' to -39
  converts '-38' to -38
  converts '-37' to -37
  converts '-36' to -36
  converts '-35' to -35
  converts '-34' to -34
  converts '-33' to -33
  converts '-32' to -32
  converts '-31' to -31
  converts '-30' to -30
  converts '-29' to -29
  converts '-28' to -28
  converts '-27' to -27
  converts '-26' to -26
  converts '-25' to -25
  converts '-24' to -24
  converts '-23' to -23
  converts '-22' to -22
  converts '-21' to -21
  converts '-20' to -20
  converts '-19' to -19
  converts '-18' to -18
  converts '-17' to -17
  converts '-16' to -16
  converts '-15' to -15
  converts '-14' to -14
  converts '-13' to -13
  converts '-12' to -12
  converts '-11' to -11
  converts '-10' to -10
  converts '-9' to -9
  converts '-8' to -8
  converts '-7' to -7
  converts '-6' to -6
  converts '-5' to -5
  converts '-4' to -4
  converts '-3' to -3
  converts '-2' to -2
  converts '-1' to -1
  converts '0' to 0
  converts '1' to 1
  converts '2' to 2
  converts '3' to 3
  converts '4' to 4
  converts '5' to 5
  converts '6' to 6
  converts '7' to 7
  converts '8' to 8
  converts '9' to 9
  converts '10' to 10
  converts '11' to 11
  converts '12' to 12
  converts '13' to 13
  converts '14' to 14
  converts '15' to 15
  converts '16' to 16
  converts '17' to 17
  converts '18' to 18
  converts '19' to 19
  converts '20' to 20
  converts '21' to 21
  converts '22' to 22
  converts '23' to 23
  converts '24' to 24
  converts '25' to 25
  converts '26' to 26
  converts '27' to 27
  converts '28' to 28
  converts '29' to 29
  converts '30' to 30
  converts '31' to 31
  converts '32' to 32
  converts '33' to 33
  converts '34' to 34
  converts '35' to 35
  converts '36' to 36
  converts '37' to 37
  converts '38' to 38
  converts '39' to 39
  converts '40' to 40
  converts '41' to 41
  converts '42' to 42
  converts '43' to 43
  converts '44' to 44
  converts '45' to 45
  converts '46' to 46
  converts '47' to 47
  converts '48' to 48
  converts '49' to 49
  converts '50' to 50
  converts '51' to 51
  converts '52' to 52
  converts '53' to 53
  converts '54' to 54
  converts '55' to 55
  converts '56' to 56
  converts '57' to 57
  converts '58' to 58
  converts '59' to 59
  converts '60' to 60
  converts '61' to 61
  converts '62' to 62
  converts '63' to 63
  converts '64' to 64
  converts '65' to 65
  converts '66' to 66
  converts '67' to 67
  converts '68' to 68
  converts '69' to 69
  converts '70' to 70
  converts '71' to 71
  converts '72' to 72
  converts '73' to 73
  converts '74' to 74
  converts '75' to 75
  converts '76' to 76
  converts '77' to 77
  converts '78' to 78
  converts '79' to 79
  converts '80' to 80
  converts '81' to 81
  converts '82' to 82
  converts '83' to 83
  converts '84' to 84
  converts '85' to 85
  converts '86' to 86
  converts '87' to 87
  converts '88' to 88
  converts '89' to 89
  converts '90' to 90
  converts '91' to 91
  converts '92' to 92
  converts '93' to 93
  converts '94' to 94
  converts '95' to 95
  converts '96' to 96
  converts '97' to 97
  converts '98' to 98
  converts '99' to 99
  converts '100' to 100
  raises an error for "-ab"
  raises an error for "ab"

Finished in 0.09698 seconds
203 examples, 0 failures
Something went wrong with that request. Please try again.