Is it possible to tell ruby to alert only once, and not several times?
class SoylentGreen
def eat
warn "Algae harvesting not implemented. Soylent green is people!"
end
end
5.times do
soylent_green = SoylentGreen.new
soylent_green.eat
end
produces
Algae harvesting not implemented. Soylent green is people!
Algae harvesting not implemented. Soylent green is people!
Algae harvesting not implemented. Soylent green is people!
Algae harvesting not implemented. Soylent green is people!
Algae harvesting not implemented. Soylent green is people!
whereas ideally I would like this to happen only once.
I do not use rails and have access to ruby 1.8 and 1.9.
Alternatives would include recording my own warning system (which closed only deliberate warnings like this), or putting a warning outside SoylentGreen#eat(which would cause it to display even if the method was not called).
source
share