Newbie question re: variable assignment

Thanks Patrick.

If I want to convert in the other direction - i.e get the ASCII value
for the characters (1..9)...

1.upto(9) { |x| puts ?x }

Does not work - it give me the ASCII code for x (which is 120) nine
times

How can I force ruby to treat the "x" as a variable and not as "x". ($x
from perlland)

Thanks

SM

···

-----Original Message-----
From: Patrick Hurley [mailto:phurley@gmail.com]
Sent: 13 April 2005 19:00
To: ruby-talk ML
Subject: Re: newbie question re: variable assignment

On 4/13/05, Simon.Mullis@equinoxsolutions.com <Simon.Mullis@equinoxsolutions.com> wrote:

Shall we find out?

We want to be the friendly news group, so starting out questions are
welcome :slight_smile:

Why doesn't this work?

1.upto(9) do |x|
        puts ?#{x}
end

The #{ } escape is for with quoted strings. You could do something
similar to what you write using and eval; however, I think you would be
better off with:

65.upto(75) { |x| puts x.chr }

Patrick

------------------------------------------------------------------------------------------
Equinox Converged Solutions
Tel: +44 (0)1252 405 600
http://www.equinoxsolutions.com
Equinox Converged Solutions is a trading name of Synetrix Holdings Limited.

IMPORTANT NOTICE:
This message is intended solely for the use of the Individual or organisation to whom it is addressed. It may contain privileged or confidential information. If you have received this message in error, please notify the originator immediately.
If you are not the intended recipient, you should not use, copy, alter, or disclose the contents of this message. All information or opinions expressed in this message and/or any attachments are those of the author and are not necessarily those of Synetrix Holdings Limited.
Synetrix Holdings Limited accepts no responsibility for loss or damage arising from its use, including damage from virus.
-------------------------------------------------------------------------------------------

Just to clarify things, the ?<char> notation is a literal value, not a
function call of any sort. It's analogous to constructs like 0xFF
(literal hex number) or for that matter 1.45 (literal floating point
value).

martin

···

Simon.Mullis@equinoxsolutions.com wrote:

If I want to convert in the other direction - i.e get the ASCII value
for the characters (1..9)...

1.upto(9) { |x| puts ?x }

Does not work - it give me the ASCII code for x (which is 120) nine
times

How can I force ruby to treat the "x" as a variable and not as "x". ($x
from perlland)