Re: hash, key, problem...
- From: Srijayanth Sridhar <srijayanth@xxxxxxxxx>
- Date: Wed, 18 Jun 2008 04:49:53 -0500
On Wed, Jun 18, 2008 at 3:09 PM, psy <psy@xxxxxxxxxxxxxxxx> wrote:
Hallo people,
I cant get something done since a while. Its very basic stuff.. :(
I have the following hash for example :
hash = { $-a => "info", $F => "another info"}
and so on, you get the meaning..
Now i use Hash#each_pair so i get the value of the variables and the
info, but I would like also to get a simple string, containing
the name of the variable, so it should look like this :
$-a
info
false
$F
another info
nil
Do you want something like this:
hash={:name => "John Doe", :age => 23}
hash.each do |elem|
puts elem.join("\n")
end
That should work. You can also of course get the string as:
string=elem.join("\n")
Hope that helps.
Jay
But I cant get it done. Its probably very stupid question, but doesnt
matter what I try - i dont get the name of the key, i always get the
key itself returned... Can somebody help me?
Thanks in advance.
Katja
.
- Follow-Ups:
- Re: hash, key, problem...
- From: psy
- Re: hash, key, problem...
- References:
- hash, key, problem...
- From: psy
- hash, key, problem...
- Prev by Date: Re: hash, key, problem...
- Next by Date: Re: quick question about how array objects are handled
- Previous by thread: Re: hash, key, problem...
- Next by thread: Re: hash, key, problem...
- Index(es):
Relevant Pages
|
Loading