From: Sebastian Hungerecker Date: 2008-11-16T19:39:48+09:00 Subject: Re: Newbie question - Problem understanding W(p)GTR Gill Abar wrote: > Why is @@syllables divided into two hashes? Why is it an array in the > first place? One hash for the first part of the name and one hash for the second, I assume. > And secondly, "syllables.shift[p]". Playing around I gathered that the > .shift[p] method returns the result of hash[p] and extracts the pair > from the hash. First of all there is no shift[p] method. There's just the shift method. And when you were "gathering around" you were asking about the Hash#shift method which is not used here. The code calls shift on the array, not on the hash. shift will return the first hash the first time and the second hash the second time. Then you call [p] on that hash. I.e. you take the value from the hash whose key equals p. > Yet I was told that the [p] part isn't an argument! So I > can't seem to fully understand this code.. See above. > It doesn't seem to work when I join the two hashes into one, and, again, > I can't understand why. Yes, because then you actually call shift on the hash and not on an array and the return value will be one key-value pair and not a hash. Then you try to call [p] on that key-value pair, but that doesn't work, because you could only call [0] or [1] on it, but not ["somestring"], but p will be a string here. HTH, Sebastian -- Jabber: sepp2k@jabber.org ICQ: 205544826