DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Emad has posted 58 posts at DZone. View Full User Profile

converting integer to an Array in #ruby

03.02.2014
| 1426 views |
  • submit to reddit
class Integer
	def to_a
		arr = []
		tmp = self
		while tmp>0
			arr << tmp%10
			tmp /= 10
		end
		arr.reverse
	end
end

# usage
print 32455.to_a
print 433456.to_a
print 345434.to_a.sort
print 344543.to_a.join '-'