ruby-enumerables-generalized-map-and-reduce-lab-online-web-prework

时间:2021-03-15 12:24:39
【文件属性】:
文件名称:ruby-enumerables-generalized-map-and-reduce-lab-online-web-prework
文件大小:11KB
文件格式:ZIP
更新时间:2021-03-15 12:24:39
Ruby 广义地图和归约实验室 学习目标 识别使用块可以避免的重复 陈述构造块的两种方法 从方法内执行块 说明yield关键字的目的 在方法和块之间传递数据 介绍 如您在上一课中所看到的,在我们各种基于map的方法和基于reduce的方法之间有很多重复的代码。 这会在您体内引发“过敏”React。 您学会了“ DRY out”您的代码。 在本课程中,我们将学习使用Ruby的强大语言功能(即block)来干燥我们自己开发的可枚举方法。 识别块可以避免的重复 让我们看一下上一课中的解决方案代码: def map_to_negativize ( source_array ) new = [ ] i = 0 while i < source_array . length do new . push ( source_array [ i ] * - 1 ) # <== Unique wo
【文件预览】:
ruby-enumerables-generalized-map-and-reduce-lab-online-web-prework-master
----CONTRIBUTING.md(2KB)
----Gemfile(53B)
----Gemfile.lock(627B)
----spec()
--------generalized_map_and_reduce_spec.rb(2KB)
--------spec_helper.rb(3KB)
----LICENSE.md(1KB)
----.gitignore(215B)
----.learn(35B)
----lib()
--------my_code.rb(17B)
----README.md(9KB)

网友评论