Validating Object Initialization Using Metaprogramming
Join the DZone community and get the full member experience.Join For Free
Source: Common Ruby Idioms [stackoverflow.com]
class Ticket @remaining = 3 def self.new if @remaining > 0 @remaining -= 1 super else "IOU" end end end Ticket.new #=> Ticket Ticket.new #=> Ticket Ticket.new #=> Ticket Ticket.new #=> "IOU"
Opinions expressed by DZone contributors are their own.