0
0
Rubyprogramming~30 mins

Any?, all?, none? predicates in Ruby - Mini Project: Build & Apply

Choose your learning style9 modes available
Using Any?, All?, and None? Predicates in Ruby
📖 Scenario: You are working on a simple system that checks a list of tasks to see if they meet certain conditions. This helps you decide if all tasks are done, if any task is urgent, or if none are overdue.
🎯 Goal: Build a Ruby program that uses any?, all?, and none? methods to check conditions on a list of tasks.
📋 What You'll Learn
Create an array of hashes called tasks with specific task details
Create a variable urgent_threshold to define urgency
Use any? to check if any task is urgent
Use all? to check if all tasks are completed
Use none? to check if no tasks are overdue
Print the results exactly as specified
💡 Why This Matters
🌍 Real World
Checking lists of tasks or items to quickly find if any, all, or none meet certain conditions is common in apps like to-do lists, inventory checks, or quality control.
💼 Career
Understanding these predicates helps in writing clean, readable code for filtering and decision-making in software development.
Progress0 / 4 steps
1
Create the tasks array
Create an array called tasks with these exact hashes: {name: 'Laundry', completed: false, days_overdue: 0}, {name: 'Homework', completed: true, days_overdue: 2}, {name: 'Grocery Shopping', completed: false, days_overdue: 5}
Ruby
Need a hint?

Use square brackets [] to create an array and curly braces {} for each task hash.

2
Set the urgency threshold
Create a variable called urgent_threshold and set it to 3 to define how many days overdue makes a task urgent
Ruby
Need a hint?

Just assign the number 3 to the variable urgent_threshold.

3
Check tasks with any?, all?, and none?
Use any? on tasks to check if any task's days_overdue is greater than urgent_threshold and save it in any_urgent. Use all? to check if all tasks are completed and save it in all_completed. Use none? to check if no tasks have days_overdue greater than 0 and save it in none_overdue.
Ruby
Need a hint?

Use blocks with any?, all?, and none? to check the conditions on each task.

4
Print the results
Print the values of any_urgent, all_completed, and none_overdue each on its own line using puts.
Ruby
Need a hint?

Use puts to print each variable on its own line.