今天效率还行,一晚上把 rubymonk 的题基本做完了,最后一章《Functional Programming in Ruby - Lambdas and Blocks》的英文太晦涩了,只做了 3 道,还有 2 道就可以完结了。不过这两道题有难度,没搞清楚概念还是做不了。
http://rubymonk.com/chapters/9-more-ruby/lessons/42-functional-programming-in-ruby
关键这一章的英文也不怎么读的懂。
我只做出 Lambdas vs. Blocks 的第一道,后面两道求帮助。顺便帮忙翻译下英文。
class Array
def transmogrify # see? no 'fn' parameter. magic.
result = []
each do |pair|
# how do you think 'yield' will be used here?
result << yield(pair)
end
result
end
end
def names
[["Christopher", "Alexander"],
["John", "McCarthy"],
["Joshua", "Norton"]].transmogrify do |pair|
# by passing the entire element, we give more control to the block
pair[0] + " " + pair[1]
end
end