🌍 The Odin Project · flashcards

The Odin Project Ruby Flashcards

50 question-and-answer cards covering Ruby as it is examined in The Odin Project. 24 of them are printed below, taken from across the deck — no signup, no paywall on the preview.

50Cards in deck
24Free preview
34Syllabus topics
~257Chars per answer
FreePrice

24 sample cards from the Ruby deck

Sampled from the end of the deck, so these are different cards from the ones shown on the syllabus page.

  1. What does a Ruby method return if there is no explicit return statement?

    The value of the last evaluated expression — this is called implicit return, and it is the idiomatic Ruby style. An explicit return keyword is used mainly to exit a method early.

  2. What do the ? and ! suffixes conventionally mean on Ruby method names?

    A ? suffix marks a predicate method that returns true or false (e.g., even?, empty?). A ! suffix marks a bang method that mutates its caller in place (e.g., upcase! changes the original string, while upcase returns a new one) or is otherwise the 'dangerous' version.

  3. How do default parameters work in Ruby methods?

    A parameter can be given a default value in the definition, e.g., def greet(name = "stranger"). If the caller omits the argument, the default is used; if provided, the argument overrides it. Parameters with defaults should come after required ones.

  4. What does binding.pry do when debugging Ruby code?

    It pauses program execution at that line and opens an interactive REPL (from the pry-byebug gem) where you can inspect and change variables in the current scope, then continue stepping through with commands like next, step, and continue.

  5. When reading a Ruby stack trace, which line matters most and what does it tell you?

    The first (top) line — it shows the file, line number, and method where the error was actually raised, plus the error type and message (e.g., NoMethodError: undefined method 'upcase' for nil). Lines below trace the chain of calls that led there.

  6. What are the three main ways to debug a Ruby program covered by The Odin Project?

    1) Read the stack trace to locate and understand the raised exception; 2) sprinkle puts/p statements to inspect values at runtime (p shows nil and types clearly); 3) use a debugger like pry-byebug to pause execution and step through code interactively.

  7. What is the key difference between #each and #map in Ruby?

    Both iterate over a collection, but #each returns the original collection unchanged (used for side effects like printing), while #map (alias #collect) returns a new array containing the block's return value for each element (used for transformation).

  8. What do the enumerable methods #select and #reject do?

    #select (alias #filter) returns a new collection containing only the elements for which the block returns true; #reject does the opposite, returning elements for which the block returns false. Neither mutates the original (their ! versions do).

  9. How does #reduce (alias #inject) work in Ruby, and how would you sum an array with it?

    It folds a collection into a single value using an accumulator: [1,2,3].reduce { |sum, n| sum + n } returns 6, computing $\sum_{i} a_{i}$. An optional argument sets the accumulator's initial value, e.g., reduce(10).

  10. What do the enumerable predicates #include?, #any?, #all?, and #none? return?

    #include?(x) — true if the collection contains x; #any? — true if the block is true for at least one element; #all? — true if the block is true for every element; #none? — true if the block is true for no elements. All return booleans.

  11. How do #each_with_index and #each_with_object differ in Ruby?

    #each_with_index yields each element along with its integer index (element, index). #each_with_object(obj) yields each element plus a memo object you build up (like a hash or array) and returns that object at the end — similar to reduce but the memo is passed, not returned, by the block.

  12. In the Caesar Cipher, what is the formula for encrypting a letter, and what does it mean?

    $E(x) = (x + n) \bmod 26$, where $x$ is the letter's position in the alphabet ($0$–$25$) and $n$ is the shift factor. Each letter is shifted $n$ positions forward, wrapping past 'z' back to 'a' thanks to the modulo.

  13. In the Odin Project Caesar Cipher, how do you handle wrap-around and non-letter characters?

    Wrap-around: apply modulo 26 to the shifted alphabet position (so 'z' with shift 1 becomes 'a'), handling uppercase and lowercase within their own ranges. Non-letter characters (spaces, punctuation) must pass through unchanged, and letter case must be preserved.

  14. What is the goal of the Odin Project Sub Strings exercise, and what is the standard approach?

    Write a method that takes a string and a dictionary array and returns a hash counting how many times each dictionary word appears as a substring, case-insensitively. Standard approach: downcase the input, then iterate the dictionary (e.g., with each_with_object or reduce), using String#scan or #include? to count matches — "below" matches both "below" and "low".

  15. What is the rule and goal of the Odin Project Stock Picker exercise?

    Given an array of daily stock prices, return the pair of indices [buy_day, sell_day] that maximizes profit $= p_{sell} - p_{buy}$, with the constraint that you must buy before you sell ($buy < sell$). The efficient solution scans once, tracking the minimum price so far and the best profit found.

  16. Describe how the bubble sort algorithm works.

    Repeatedly step through the array comparing adjacent pairs; if a pair is out of order, swap them. After each full pass the largest unsorted element 'bubbles up' to its final position at the end. Repeat passes until a complete pass makes no swaps, meaning the array is sorted.

  17. What is the time complexity of bubble sort in the worst and best cases?

    Worst and average case: $O(n^{2})$, because up to $n$ passes each do up to $n$ comparisons. Best case (already sorted, with the no-swap early exit optimization): $O(n)$, one pass with zero swaps. Space complexity is $O(1)$ since it sorts in place.

  18. In a Ruby class, what is the initialize method and what are instance variables?

    initialize is the constructor that runs automatically when you call ClassName.new(args). Instance variables start with @ (e.g., @name) and hold state unique to each object instance; they are accessible from any instance method of the class but not from outside without accessor methods.

  19. What do attr_reader, attr_writer, and attr_accessor generate in a Ruby class?

    They auto-generate methods for instance variables: attr_reader :name creates a getter (name), attr_writer :name creates a setter (name=), and attr_accessor :name creates both. They replace hand-written trivial getter/setter methods.

  20. How do instance methods/variables differ from class methods/variables in Ruby?

    Instance methods are called on objects and use @variables unique to each instance. Class methods are defined with self. (def self.method) and called on the class itself; class variables use @@ and are shared by the class and all its instances (and subclasses, which makes @@ risky).

  21. How does inheritance work in Ruby, and what does super do?

    A subclass inherits with <, e.g., class Dog < Animal, gaining all of Animal's methods. super inside an overriding method calls the parent's version of that same method — super passes the same arguments along, super() passes none.

  22. What does marking methods private in a Ruby class accomplish?

    Methods below the private keyword can only be called from within the object's other instance methods, not from outside (no explicit receiver). This enforces encapsulation: the public interface stays small while internal helper logic is hidden from users of the class.

  23. What is the difference between require and require_relative when organizing a multi-file Ruby project?

    require loads from Ruby's load path (installed gems and standard library), e.g., require 'json'. require_relative loads a file by its path relative to the current file, e.g., require_relative 'lib/board' — the standard way to split your own project into multiple files.

  24. What is RuboCop and what do the commands rubocop and rubocop -a do?

    RuboCop is Ruby's standard linter and formatter that enforces the community Ruby Style Guide through rules called 'cops'. Running rubocop reports offenses; rubocop -a (autocorrect) safely fixes many of them automatically. Project-specific rules are configured in a .rubocop.yml file.

What this deck covers

The Ruby deck follows the The Odin Project Ruby syllabus — 8 chapters and 34 topics — so questions land on material that is genuinely examinable rather than trivia around it. That works out to roughly 6.3 cards per chapter.

Answers are written to be recallable, not just readable — averaging about 257 characters, which is long enough to carry the reasoning and short enough to say out loud.

A deck like this earns its keep on the second and third pass. Read the syllabus first so you know the shape of the subject, then use the cards to find the specific facts that have not stuck.

Ruby flashcards FAQ

How many Ruby flashcards are in this The Odin Project deck?

50 cards. This page previews 24 of them, sampled evenly across the deck so you can judge the difficulty before installing anything.

Are these The Odin Project flashcards free?

Yes. The preview here is free to read with no signup, and the full 50-card deck is free inside the Examius app.

What do the Ruby cards cover?

They follow the The Odin Project Ruby syllabus — 8 chapters and 34 topics — so the questions track what is actually examinable.

How should I use these flashcards?

Read the syllabus first so you know the shape of the subject, then drill the deck. Examius schedules each card with spaced repetition, so cards you keep missing come back sooner and ones you know drift further apart.