0Pricing
Ruby Academy · Lesson

The Enumerable Module

Shared collection powers.

What Is Enumerable?

Enumerable is a module that gives collections like arrays, hashes, and ranges a shared set of powerful methods. Any class with each can mix it in.

puts [1, 2, 3].is_a?(Enumerable)
puts (1..3).is_a?(Enumerable)

include? and member?

include? checks whether a collection contains a value.

nums = [10, 20, 30]
puts nums.include?(20)
puts (1..5).include?(3)

All lessons in this course

  1. Creating Ranges
  2. The Enumerable Module
  3. map, select, reject
  4. reduce and each_with_object
← Back to Ruby Academy