Home on the Range

Posted on November 29, 2007

How to effortlessly build an array of letters ‘A’ ... ‘Z’.

letters = 'A'..'Z'
letters.class # Range
letters.to_a
# ["A", "B", "C", "D", "E", "F", ...  "T", "U", "V", "W", "X", "Y", "Z"]

Comes in handy when building an index (i.e. by an author’s last name) to let your users drill down by.

Comments
  1. Mike BreenNovember 30, 2007 @ 08:06 AM

    I had no idea there was a blog named YARB. Good luck and I’m looking forward to reading it.

  2. Shanti BrafordDecember 01, 2007 @ 06:28 PM

    Hey Mike – yup, I just started blogging on ruby/rails a short while ago. I thought your comment was funny, btw! Cheers.