Complete the code to return early if the number is negative.
def check_number(num) return 'Negative number' if [1] 'Number is positive' end
The guard clause checks if num is less than zero to return early.
Complete the guard clause to return early if the string is empty.
def greet(name) return 'No name provided' if [1] "Hello, #{name}!" end
nil? misses empty strings that are not nil.The guard clause uses empty? to check if the string has no characters.
Fix the error in the guard clause to correctly return if the array is nil or empty.
def process_list(list) return 'No items' if [1] list.map(&:upcase) end
The guard clause uses || to check if list is either nil or empty.
Fill both blanks to create a guard clause that returns early if the user is not logged in or inactive.
def access_page(user) return 'Access denied' if [1] || [2] 'Welcome!' end
The guard clause returns if the user is not logged in or not active.
Fill all three blanks to create a guard clause that returns early if the input is nil, empty, or not a string.
def validate_input(input) return 'Invalid input' if [1] || [2] || [3] 'Input is valid' end
input.length == 0 without checking for nil causes errors.The guard clause checks if input is nil, empty, or not a string, returning early if any are true.