Is it possible to tell ruby to give a warning only once, rather than multiple 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'd like it to occur only once.
I'm not using rails, and have access to ruby 1.8 and 1.9.
Alternatives would include writing my own warning system (which'd cover only deliberate warnings like this), or putting the warning outside of SoylentGreen#eat
(which'd cause it to be displayed even if the method wasn't called).