想请教关于 learn ruby the hard way Exercise41 的一段程式码
http://learnrubythehardway.org/book/ex41.html
在oop_test.rb这个档案里面有一段
从
50 param_names = craft_params(rand_words, snippet, /@@@/)
跳到
36 def craft_params(rand_words, snippet, pattern)
37 names = (0...snippet.scan(pattern).length).map do
38 param_count = rand(3) + 1
39 params = (0...param_count).map {|x| rand_words.pop() }
40 params.join(', ')
41 end
42
43 return names * 2
44 end
这段看不太懂,
我尝试 puts (0...snippet.scan(pattern).length).map
但是印出来的结果是 #<Enumerator:0x000000028ee138> <==??
接下来我尝试
puts (0...3).map
结果是只出现一个 #<Enumerator:0x000000028653b0>
而不是
#<Enumerator:0x000...>
#<Enumerator:0x000...>
#<Enumerator:0x000...>
这样的话假设我的param_count = 3
那39行怎么知道要pop三个word出来呢?