Printing variable names

Hello all,

I have an array of variables here:

foo = [s0, s1, s2, s3, s4, s5, s6, s7]

I need to loop over the array and print each variable's name and value:

s0: 23
s1: 56
s2: 345345

etc....

I cannot seem to find a way to print the name. Is it possible?

Thanks for consideration,
-d

···

--
darren kirby :: Part of the problem since 1976 :: http://badcomputer.org
"...the number of UNIX installations has grown to 10, with more expected..."
- Dennis Ritchie and Ken Thompson, June 1972

I cannot seem to find a way to print the name. Is it possible?

Thanks for consideration,
-d

Wouldn't it be more logical to use a hash?

···

--
Posted via http://www.ruby-forum.com/\.

quoth the Haze Noc:

> I cannot seem to find a way to print the name. Is it possible?
>
> Thanks for consideration,
> -d

Wouldn't it be more logical to use a hash?

Perhaps, but the order of the variables is significant. I was thinking I might
create a hash to map the position to the name and vice versa...

Basically what I need to do here is allow all these variables to be accessed
by name and by position. The name of the vars is significant, and I need the
user to be able to dump the values to see each one, hence the original
question.

Perhaps I will think about this more and see if I cannot formulate my needs a
bit better...

Thanks,
-d

···

--
darren kirby :: Part of the problem since 1976 :: http://badcomputer.org
"...the number of UNIX installations has grown to 10, with more expected..."
- Dennis Ritchie and Ken Thompson, June 1972

quoth the darren kirby:

quoth the Haze Noc:
> > I cannot seem to find a way to print the name. Is it possible?
> >
> > Thanks for consideration,
> > -d
>
> Wouldn't it be more logical to use a hash?

Perhaps, but the order of the variables is significant. I was thinking I
might create a hash to map the position to the name and vice versa...

OK, answered my original question:
    
@registers = [:zero, :at, :v0, :v1, :a0, :a1, :a2, :a3,
  :t0, :t1, :t2, :t3, :t4, :t5, :t6, :t7,
  :s0, :s1, :s2, :s3, :s4, :s5, :s6, :s7,
  :t8, :t9, :k0, :k1, :gp, :sp, :fp, :ra]

@registers.each do |v|
  puts "$#{v}: #{send(v)}"
end

...

-d

···

--
darren kirby :: Part of the problem since 1976 :: http://badcomputer.org
"...the number of UNIX installations has grown to 10, with more expected..."
- Dennis Ritchie and Ken Thompson, June 1972