From: Timothy Hunter Date: 2006-06-27T08:50:59+09:00 Subject: Re: Quick quesiton abt an array of characters.. brez! !! wrote: > This seems like it'd be obvious but haven't had any luck with it.. > > Let's say I want to build an array of characters in order, i.e. > > characters = ['a','b','c','d',..] > > If they were numbers I could do this: > > r = [] > (0..9).each { |x| r << x} > > but how to do for characters? > > Thanks > > irb(main):006:0> r = [] => [] irb(main):007:0> ('a'..'z').each {|d| r << d} => "a".."z" irb(main):008:0> r => ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"] or irb(main):009:0> r = [] => [] irb(main):010:0> c = 'a' => "a" irb(main):011:0> 26.times { r << c; c = c.succ} => 26 irb(main):012:0> r => ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]