Programming paths / Ruby

Ruby learning path

Learn expressive Ruby for web applications, automation, and maintainable domain-focused code.

Starter lesson

Select records with a clear predicate

Enumerable methods let a collection describe what it is doing. Use a predicate that states the rule and keep the source collection unchanged.

tasks = [
  { title: "Write tests", ready: true },
  { title: "Review logs", ready: false }
]

ready_titles = tasks
  .select { |task| task.fetch(:ready) }
  .map { |task| task.fetch(:title) }

puts ready_titles

What to expect

Write tests

Key idea: Prefer explicit keys and collection methods that make the data transformation easy to read.

← Browse all programming paths