Re: hash, key, problem...



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



.



Relevant Pages

  • Re: Lots of help needed urgently
    ... will reveal the passwords that are usually displayed on-screen as a string ... of asterisks. ... > him for help `cos I cant send him an email. ... > COME ON Guys `n Gals help an old dumbass out of this ...
    (microsoft.public.security)
  • Re: Concatenate field as PK
    ... Prov, Cant, Dist, Bloq, Sect and NumParc. ... CodSig (string) ... NumPar (string) ...
    (microsoft.public.access.forms)
  • Re: function to change metric measurements
    ... i requre a little bit of guidance and help to right a simple function ... by a string or value to show that i want the result converting in to ... even though i passing the mm's to the function as a number i wish it to ... I know this should be easy but i just cant seem how i should structure my ...
    (microsoft.public.excel.worksheet.functions)
  • function to change metric measurements
    ... a string or value to show that i want the result converting in to ... I know this should be easy but i just cant seem how i should structure my ... as i done something similar for inches and passing the factor of the inches ...
    (microsoft.public.excel.worksheet.functions)
  • .Split a directory string
    ... I cant seem to get it to work? ... Compilation Error ... Compiler Error Message: CS1502: The best overloaded method match for ... Line 234: string strFileNameOnServer = txtServername.Value; ...
    (microsoft.public.dotnet.languages.csharp)

Loading