From: Robert Klemme Date: 2005-04-14T03:24:38+09:00 Subject: Re: newbie question re: variable assignment "Trans" schrieb im Newsbeitrag news:1113415954.205046.176340@z14g2000cwz.googlegroups.com... > Hi-- > Dont; worry this is a low bite board :-) > >> Why doesn't this work? >> >> 1.upto(9) do |x| >> puts ?#{x} >> end > > Well, its cuz you're trying to do string interpolation directly into > ruby code, which can't be done. The interpolation (i.e. #{x}) only > works in strings. Secondly, the ? is a literal form and not a method, > so you can;t pass it arguments. To get the ascii value of a string use > str[n] where n is the index of the character you wish to convert, in > this case 0. > > 1.upto(9) do |x| > puts "#{x}"[0] > end or 1.upto(9) do |x| puts x.to_s[0] end or (with some knowledge of ASCII characterset) 1.upto(9) do |x| puts ?0 + x end > BTW, I believe this will change in future verions of Ruby since Ruby > will be gaining more advanced encoding. So instead there will be a > specific method, like String#ascii(n), or something, to do this. > [Correct me if I am misinformed all.] But for now the above is the way. Yeah probably. But for the time being your solution works. Kind regards robert