3 ms·
Author here, wow that's great! I am still learning Ruby (hence the article to try to grok things).
by softwaredoug 5y ago
Author here, wow that's great! I am still learning Ruby (hence the article to try to grok things).
- pelasaco 5y agoas suggestion, regarding the following code: Stuff.new().each do |item| puts item end In idiomatic ruby, we drop this parenthesis, so the code will look like Stuff.new.each ...
- hirundo 5y agoputs Stuff.new.map(&:to_s).join("\n")
- usefulcat 5y agoIf one is having to implement an each or map or select method in ruby, then I can definitely appreciate the differences you point out. Even though I've been using ruby a long time, it would frankly still be a bit of a pain to have to remember the details of how yield works. Because Enumerable provides so much functionality, I almost never need to implement methods like those. So what I really care about a lot more are the ergonomics of using each, map, select, reject, all?, any?, etc, which I use very frequently.
- softwaredoug 5y agoYes though the point is the same, Enumerable gives the objects methods (internal iteration), in Python you would use built-ins max or filter or a list comprehension on an iterator (external iteration).