Skip to content

Instantly share code, notes, and snippets.

@emad-elsaid
Created February 19, 2014 10:50
Show Gist options
  • Save emad-elsaid/9089725 to your computer and use it in GitHub Desktop.
Save emad-elsaid/9089725 to your computer and use it in GitHub Desktop.
convert integer to array in ruby
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 '-'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment