From: John Joyce Date: 2007-07-18T07:42:20+09:00 Subject: Re: type conversion On Jul 17, 2007, at 5:05 PM, Ian Whitlock wrote: > Shandy Nantz wrote: >> So there is an to_s for strings and a to_i for integers. However, >> if I >> have an array of integers and I want to grab one, I get back and >> ASCII >> character. For example, when I grab a 1 from the array it returns >> a 49 - >> but I wanted the one! How do I convert it back to its integer >> want-to-be? Thanks, >> >> ~S >> >> P.S. I imagine this is probably an easy solution but, I am a ruby >> newbie. > > Shandy, Perhaps this helps. Note the difference between 004 and 006 > > irb(main):003:0> i = "1234" > => "1234" > irb(main):004:0> i[0] > => 49 > irb(main):005:0> i[0].class > => Fixnum > irb(main):006:0> i[0,1] > => "1" > irb(main):007:0> i[0,1].class > => String > irb(main):008:0> i[0,1].to_i > => 1 > irb(main):009:0> i[0,1].to_i.class > => Fixnum > > -- > Posted via http://www.ruby-forum.com/. > arr = "1234" Will only give you a string. You need : arr = Array.new arr << 1 arr << 2 ... OR arr = [1,2,3,4,] At the command line, use ri: ri Array ri '[]=' ri 'Array#[]=' ri 'String#[]='