Typically, functions that iterate over return an enumerated (e.g. array) that has been iterated. If you do this, you can check if this return value is empty:
if my_function(){ |item| โฆ }.empty? puts "nothing found!" end
Of course, if your block is on several lines, it might make sense to write this as:
items = my_function() do |item| # โฆ end puts "Nothing found!" if items.empty?
If it is not easy or efficient for you to create an enumerable that you repeated, you just need to change your function to return a boolean at the end indicating that you have repeated something.
source share