Newbie question - Problem understanding W(p)GTR

Thread Solved

Join Date: Nov 2008
Posts: 2
Reputation: Ziga is an unknown quantity at this point 
Solved Threads: 0
Ziga Ziga is offline Offline
Newbie Poster

Newbie question - Problem understanding W(p)GTR

 
0
  #1
Nov 16th, 2008
(Repost from Ruby-Forum.com. Sorry, but I'm really etching to continue learning Ruby..)
In w(p)gtr I have found myself facing a code which, for the life of me,
I just could not understand a few thing in! Seeing as this is the
closest board realting to the subject, I shall post my question here -

The code I speak of is -
  1. class String
  2.  
  3. # The parts of my daughter's organ
  4. # instructor's name.
  5. @@syllables = [
  6. { 'Paij' => 'Personal',
  7. 'Gonk' => 'Business',
  8. 'Blon' => 'Slave',
  9. 'Stro' => 'Master',
  10. 'Wert' => 'Father',
  11. 'Onnn' => 'Mother' },
  12. { 'ree' => 'AM',
  13. 'plo' => 'PM' }
  14. ]
  15.  
  16. # A method to determine what a
  17. # certain name of his means.
  18. def name_significance
  19. parts = self.split( '-' )
  20. syllables = @@syllables.dup
  21. signif = parts.collect do |p|
  22. syllables.shift[p]
  23. end
  24. signif.join( ' ' )
  25. end
  26.  
  27. end

Now, what I could not understand is:
  • Why is @@syllables divided into two hashes? Why is it an array in the
    first place?
  • 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. Yet I was told that the [p] part isn't an argument! So I
    can't seem to fully understand this code..

It doesn't seem to work when I join the two hashes into one, and, again,
I can't understand why.

It is probably just a little thing I'm missing, or some-such event. If
anyone could be of assistance, I will be very grateful.

Yours,
-Gill
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 2
Reputation: Ziga is an unknown quantity at this point 
Solved Threads: 0
Ziga Ziga is offline Offline
Newbie Poster

Re: Newbie question - Problem understanding W(p)GTR

 
1
  #2
Nov 17th, 2008
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the Ruby Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC