| | |
Newbie question - Problem understanding W(p)GTR
Please support our Ruby advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Nov 2008
Posts: 2
Reputation:
Solved Threads: 0
(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 -
Now, what I could not understand is:
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
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)
class String # The parts of my daughter's organ # instructor's name. @@syllables = [ { 'Paij' => 'Personal', 'Gonk' => 'Business', 'Blon' => 'Slave', 'Stro' => 'Master', 'Wert' => 'Father', 'Onnn' => 'Mother' }, { 'ree' => 'AM', 'plo' => 'PM' } ] # A method to determine what a # certain name of his means. def name_significance parts = self.split( '-' ) syllables = @@syllables.dup signif = parts.collect do |p| syllables.shift[p] end signif.join( ' ' ) end 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
![]() |
Other Threads in the Ruby Forum
- Previous Thread: destructors in ruby
- Next Thread: Q & A: SpringSource CEO Rod Johnson
| Thread Tools | Search this Thread |





