til

Today I Learned: collection of notes, tips and tricks and stuff I learn from day to day working with computers and technology as an open source contributor and product manager

View project on GitHub

Split an Integer into an Array

I needed this for implementing a arabic to roman numeral converter. I needed to split the integer into an array of its digits.

digit = 123
digits = digit.to_s.chars.map(&:to_i)

puts digits.inspect

And if you want to reverse the array, you can use the reverse method.

digit = 123
digits = digit.to_s.chars.reverse.map(&:to_i)

puts digits.inspect

Resources and References