Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Validating Object Initialization Using Metaprogramming

DZone's Guide to

Validating Object Initialization Using Metaprogramming

·
Free Resource
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"


 
Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}