943,840 Members | Top Members by Rank

Ad:
  • Ruby Discussion Thread
  • Marked Solved
  • Views: 2130
  • Ruby RSS
Nov 16th, 2008
0

Newbie question - Problem understanding W(p)GTR

Expand Post »
(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 -
Ruby Syntax (Toggle Plain Text)
  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
Reputation Points: 22
Solved Threads: 0
Newbie Poster
Ziga is offline Offline
2 posts
since Nov 2008
Nov 17th, 2008
1

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

Reputation Points: 22
Solved Threads: 0
Newbie Poster
Ziga is offline Offline
2 posts
since Nov 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Ruby Forum Timeline: destructors in ruby
Next Thread in Ruby Forum Timeline: Q & A: SpringSource CEO Rod Johnson





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC