Enumerable methods, duck typing, method_missing, define_method, open classes, gems and bundler.
35 cards · basic cards · AI-written, checked twice. Edit anything.
- What is Enumerable in Ruby?
Show answer
A mixin module that provides iteration methods for collections, including map, select, reduce, and many others.
- What does the map method do?
Show answer
Iterates over each element and returns a new array with the results of the block applied to each element.
- What does the select method do?
Show answer
Iterates over elements and returns a new array containing only elements for which the block returns true.
- What does the reject method do?
Show answer
Returns a new array with elements for which the block returns false, opposite of select.
- What does reduce (or inject) do?
Show answer
Combines elements of an enumerable into a single value by repeatedly applying a block.
- What does the each method do?
Show answer
Iterates over each element, executing the block for each element, and returns the original collection.
- What does find (or detect) return?
Show answer
The first element for which the block returns true, or nil if no match is found.
- What does any? do?
Show answer
Returns true if at least one element matches the block condition, false otherwise.
- What does all? do?
Show answer
Returns true if all elements match the block condition, false if any does not match.
- What does include? check?
Show answer
Returns true if the enumerable contains the specified value, false otherwise.
- What is duck typing?
Show answer
A programming style where an object is suitable for a task if it has the right methods, regardless of type or inheritance chain.
- What does respond_to? check?
Show answer
Whether an object responds to a specified method name, returning true or false.
- How does duck typing differ from static type checking?
Show answer
Duck typing checks behavior at runtime; static typing checks class membership at compile time.
- What is a benefit of duck typing?
Show answer
Code works with any object that implements required methods, increasing reuse and flexibility.
- What is method_missing?
Show answer
A private method called when an object receives a message for a method that does not exist.