Generate array of all letters and digits

[*('a'..'z'), *('0'..'9')] # doesn't work in Ruby 1.8

or

('a'..'z').to_a + ('0'..'9').to_a

or

(0...36).map{ |i| i.to_s 36 }

(the Integer#to_s method converts a number to a string representing it in a desired numeral system)


You can also do it this way:

'a'.upto('z').to_a + 0.upto(9).to_a

for letters or numbers you can form ranges and iterate over them. try this to get a general idea:

("a".."z").each { |letter| p letter }

to get an array out of it, just try the following:

("a".."z").to_a

Tags:

Ruby