词汇:inject
vt. 注射;注入
相关场景
- 19. reduce方法折叠集合:
- Enumerable模块的类,可对集合进行过滤,遍历和转化。map和select;还有个可以管理一切的方法 reduce(or inject), reduce可以转换结构;接受者,每个元素被调用一次,并产生返回值,累加器。 enum.reduce(0){|accumulator, element| accumulator + element} 0初始值;建议你总是使用一个带有起始值的累加器。 enum.reduce(0, :+);
数组转成Hash; array.reduce({}) {|hash, element| hash.update(element => true)}
users.select{|u| u.age>=21}.map(&:name) 获取大于等于21的names数组。比较低效;
User.reduce([]) {|names, user| names << user.name if user.age >=21 ; names}>> Effective Ruby- Let her go, off into the sunset to inject another family with her poison!>> 水性杨花 Easy Virtue Movie Script
- Even inject them with poison when they were too feeble to do it for themselves.>> 水性杨花 Easy Virtue Movie Script
- Neil injects Kat in the arm. Her eyes close.>> 信条Tenet Movie Script
- THE BAT-MAN removes a syringe, labelled "stimulant", from his ammo belt and injects the needle into his biceps.>> 蝙蝠侠:元年 Batman: Year One Movie Script
- She injects Sofie with the gold syringe.>> 杀死比尔Kill Bill Movie Script
- He injects himself.>> 老无所依No Country for Old Men Movie Script