FlashKeepers

PHP and Ruby · College · College and University

Ruby II: Idioms and Metaprogramming

Enumerable methods, duck typing, method_missing, define_method, open classes, gems and bundler.

About this set

35 basic cards for College PHP and Ruby. Set 2 of 2 in Ruby. It opens with "What is Enumerable in Ruby?" and "What does the map method do?". Study it alongside the other College sets below.

35 cards · basic cards · AI-written, checked twice. Edit anything.

Study this set free Look inside first Get FlashKeepers for iPhone

Opens in your browser, no account. Get the iPhone and iPad app · Android app

What is Enumerable in Ruby?
Show answerA mixin module that provides iteration methods for collections, including map, select, reduce, and many others.
What does the map method do?
Show answerIterates 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 answerIterates over elements and returns a new array containing only elements for which the block returns true.
What does the reject method do?
Show answerReturns a new array with elements for which the block returns false, opposite of select.
What does reduce (or inject) do?
Show answerCombines elements of an enumerable into a single value by repeatedly applying a block.
What does the each method do?
Show answerIterates over each element, executing the block for each element, and returns the original collection.
What does find (or detect) return?
Show answerThe first element for which the block returns true, or nil if no match is found.
What does any? do?
Show answerReturns true if at least one element matches the block condition, false otherwise.
What does all? do?
Show answerReturns true if all elements match the block condition, false if any does not match.
What does include? check?
Show answerReturns true if the enumerable contains the specified value, false otherwise.
What is duck typing?
Show answerA 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 answerWhether an object responds to a specified method name, returning true or false.
How does duck typing differ from static type checking?
Show answerDuck typing checks behavior at runtime; static typing checks class membership at compile time.
What is a benefit of duck typing?
Show answerCode works with any object that implements required methods, increasing reuse and flexibility.
What is method_missing?
Show answerA private method called when an object receives a message for a method that does not exist.

20 more cards in the app

Study this set free