What is the Enumerable module and why is it so powerful?
Last updated
Enumerable is a mixin module that gives any collection class a huge library of iteration methods (map, select, reduce, sort, etc.) in exchange for defining a single method: each.
One method buys dozens: Define
eachandinclude Enumerable, and you get the whole traversal/transform/query toolkit for free.Consistent API everywhere:
Array,Hash,Range, andSetall share the same methods, so knowledge transfers across collections.Functional, chainable style: Methods return new collections you can chain, encouraging declarative code over manual loops.
Sorting and comparison:
min,max, andsortrely on elements implementing<=>.
[lang:ruby]
class TodoList
include Enumerable
def initialize(*items) = @items = items
def each(&block) = @items.each(&block)
end
TodoList.new("a", "b").map(&:upcase) # => ["A", "B"]
- https://www.it-jobs-nl.com/ruby-developer/
- https://www.bacancytechnology.com/blog/outsource-ruby-on-rails-development
- https://blog.nextideatech.com/how-to-hire-the-best-ruby-on-rails-developers-the-complete-guide/
- https://ubiminds.com/en-us/ruby-on-rails-developers/
- https://dataford.io/interview-guides/pattern/software-engineer
- https://www.reddit.com/r/rails/comments/1shfrbq/3_years_rails_dev_but_failed_basic_interview/