2013-02-23 48 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 
相关问题