This should be very simple. Probably embarrassing myself by asking. 🙂
Although I’m still new to ruby/rails.
I’d like to break out of a loop if a conditional has been met.
A sale is complete when all items have been sold. I’d like to be able to use sale.is_complete?.
class Sale < ActiveRecord::Base
has_many :items
def is_complete?
items.each do |item|
# as soon as i encounter an unsold item, i want to return false to is_complete
# item.is_sold? will return true or false
end
end
end
In this case, looping is not the best way.