Generate array of all letters and digits

后端 未结 7 918
温柔的废话
温柔的废话 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:27

    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
    

提交回复
热议问题