Generate array of all letters and digits

后端 未结 7 961
温柔的废话
温柔的废话 2021-01-30 07:49

Using ruby, is it possible to make an array of each letter in the alphabet and 0-9 easily?

7条回答
  •  一整个雨季
    2021-01-30 08:29

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

    or

    ('a'..'z').to_a + ('0'..'9').to_a # works in 1.8 and 1.9
    

    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)

提交回复
热议问题