2013-02-23 49 views
1

我正在研究Rails教程(http://ruby.railstutorial.org/chapters/rails-flavored-ruby#top),挑戰在於向String類添加一個shuffle方法。有人可以解釋什麼?正在做self.split('')。?。?

這是建議的解決方案:

清單4.11。骨架爲連接到String類洗牌方法:

class String 
    def shuffle 
    self.split('').?.? 
    end 
end 

很抱歉,如果這是真的很容易讓大多數人,但我是新的發展。我沒有得到什麼。?。?在做什麼?這本書沒有解釋,也不能在網上找到它。

感謝

+0

self.split( '').shuffle.join – Automatico 2013-02-23 12:24:47

回答

4

這是不建議的解決方案 - 練習寫着:

By replacing the question marks in Listing 4.10 with the appropriate methods, combine split, shuffle, and join to write a function that shuffles the letters in a given string.

Using Listing 4.11 as a guide, add a shuffle method to the String class.

你應該用正確的方法名稱來代替?的。

+1

哦。傻我。謝謝! – 2013-02-23 14:32:20

0

有同樣的問題...這裏是它應該如何看起來:

4.10

s.split('').shuffle.join 

4.11

class String 
    def shuffle 
    self.split('').shuffle 
    end 
    end 
相關問題