From: "David A. Black" Date: 2008-05-12T18:58:37+09:00 Subject: Re: Convert integer to array? Hi self -- On Mon, 12 May 2008, David A. Black wrote: > Hi -- > > On Mon, 12 May 2008, Nadim Kobeissi wrote: > >> Let's say I have: >> x=1234 >> How can I convert that to the follow array: >> x=[1, 2, 3, 4] > > require 'scanf' > "1234".scanf("%1d" * 4) > # => [1, 2, 3, 4] "%1d" * x.size would be better (no need to hard-code the 4). David -- Rails training from David A. Black and Ruby Power and Light: INTRO TO RAILS June 9-12 Berlin ADVANCING WITH RAILS June 16-19 Berlin INTRO TO RAILS June 24-27 London (Skills Matter) See http://www.rubypal.com for details and updates!