Would anyone happen to know how would I go about creating a hash where I
have more then one value equating to another?
i.e. England => Liverpool, England => London, France =>Rennes,
England=>Plymouth, France=>Paris.
I’ve tried all sorts of ways to do this but I always seem to overwrite
the old value of hash[england]=liverpool when I try and add London to
england too.
Is this even possible using a conventional hash? Or would I somehow have
to use a hash of arrays or something?
Also…Just how would I recall the values once I have them?
In my experiments I may well have stumbled across the answer but can’t
retrieve them.
Sorry for this question being rather vague but I don’t even know the
name of what I’m trying to do or anything about how to do it…I’d
appreciate any help here, at the very least even just a pointer in the
right direction.
One other minor thing- would it be possible for the the strings inside
‘France’ => [‘Rennes’, ‘Paris’]
to be variables instead?
Yes, certainly. You can easily create an array containing variables
instead
of literal strings.
Off the top of my head I think there may be some sort of symbol you’d
put before nation to show it is a actual stored string but I can’t
remember what it was…
Not in Ruby. Ruby doesn’t have characters in variable names that give
away
their type.
One other minor thing- would it be possible for the the strings inside
‘France’ => [‘Rennes’, ‘Paris’]
to be variables instead?
i.e. instead of France= those two I earlier have a ‘enter country name’
and ‘enter city 1’, ‘enter city 2’,etc…
Off the top of my head I think there may be some sort of symbol you’d
put before nation to show it is a actual stored string but I can’t
remember what it was…
One other minor thing- would it be possible for the the strings inside
‘France’ => [‘Rennes’, ‘Paris’]
to be variables instead?
i.e. instead of France= those two I earlier have a ‘enter country name’
and ‘enter city 1’, ‘enter city 2’,etc…
Off the top of my head I think there may be some sort of symbol you’d
put before nation to show it is a actual stored string but I can’t
remember what it was…
Hi,
Is the following what you try to do?
Li
##script #:england and :france (or :England and :France) are symbols in ruby