Questions
Ruby questions
Choose a question page, learn the concept, then test your understanding with a quiz.
How to Iterate Through an Array in Ruby: each, each_with_index, for, and More
Learn the right way to iterate through arrays in Ruby, including each, each_with_index, times, and hash iteration patterns.
How to Map and Remove nil Values in Ruby
Learn idiomatic Ruby ways to transform arrays and remove nil values using map, compact, filter_map, and related patterns.
How to Map with Index in Ruby
Learn how to transform arrays with both value and index in Ruby using map.with_index, each_with_index, and practical examples.
How to Match All Regular Expression Occurrences in Ruby
Learn how to find every regex match in Ruby using scan, to_enum, and MatchData with clear examples and common pitfalls.
How to Parse a JSON String in Ruby
Learn how to parse a JSON string in Ruby, access nested values safely, and avoid common mistakes with practical examples.
How to Pass Command Line Arguments to a Rake Task in Ruby
Learn how to pass command line arguments to Rake tasks in Ruby, including task parameters, environment variables, and calling tasks from other tasks.
How to Pause Execution in Ruby with sleep
Learn how to make a Ruby program wait using sleep, including syntax, examples, timing behavior, and common mistakes.
How to Pick a Random Element from an Array in Ruby
Learn how to choose a random item from an array in Ruby using Array#sample, with examples, mistakes to avoid, and practical use cases.
How to Remove Old Ruby Gem Versions and Keep the Latest
Learn how to uninstall old Ruby gem versions while keeping the newest one using RubyGems commands and safe cleanup practices.
How to Remove RVM (Ruby Version Manager) from Your System
Learn how to remove RVM from your system safely, including shell cleanup, PATH changes, and verifying Ruby environment settings.
How to Remove Whitespace in Ruby: strip, lstrip, rstrip, and gsub
Learn how to remove whitespace in Ruby using strip, lstrip, rstrip, and gsub, and how they compare to PHP trim().
How to Remove an Array Element by Value in Ruby
Learn how to delete an element from an array by value in Ruby using delete, delete_at, reject, and related array methods.
How to Replace a Word in a String in Ruby
Learn how to replace a word in a Ruby string using sub and gsub, with simple examples, common mistakes, and practical use cases.
How to Require All Files from a Directory in Ruby
Learn how to require all files from a directory in Ruby using Dir globbing, require_relative, load order, and common pitfalls.
How to Return a 404 Response in Ruby on Rails
Learn how to return or render a 404 response in Rails, when to use it, and common patterns for missing records and custom not found pages.
How to Round an Average to 2 Decimal Places in PostgreSQL
Learn why ROUND(AVG(...), 2) can fail in PostgreSQL and how to correctly round averages to 2 decimal places using numeric casting.
How to Run One Rake Task from Another in Ruby
Learn how to run Rake tasks from within other Rake tasks in Ruby, including prerequisites, reenable, invoke, and common pitfalls.
How to Run a Single RSpec Test in Rails
Learn how to run one RSpec file or a single example in Rails, including terminal commands, line numbers, and project directory setup.
How to Skip an Iteration in Ruby .each: Using next Instead of continue
Learn how to skip an iteration in a Ruby .each loop using next, with examples, common mistakes, comparisons, and practice exercises.
How to Sum an Array of Numbers in Ruby
Learn how to sum numbers in a Ruby array using sum, inject, and each, with examples, common mistakes, and a practical mini project.