Forum: Ruby Q: return Array [1,'a',2,3] ASCII value

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Some O. (Guest)
on 2006-06-04 14:46
Hi everyone,

say if I have an array [1,'a',2,3] and I want to print out the ASCII
value of each element, how do it I do it?

I tried the following

[1,'a',2,3].each {|x| p ?x}

but apparently x isnt being treated as a variable with "?x" and it will
just return the ASCII value of the charater 'x'.

Thx in advance
Some O. (Guest)
on 2006-06-04 14:48
some one wrote:
>
> [1,'a',2,3].each {|x| p ?x}
>


Okie, I found the solution...


[1,2,3,'a'].each { |x|  print x.to_s[0] }
This topic is locked and can not be replied to.