class Lego attr_reader :picks def self.count; @count = 0; end def initialize( *picks ) if picks.uniq.length != 1 raise ArgumentError, "numbers not Identical" end @picks = picks end def self.new_random new( rand( 25 ), rand( 25 ) ) rescue ArgumentError self.count += 1 retry end end Lego.new_random p Lego.count # output: # randexp.rb:14:in `new_random': undefined method `count=' for Lego:Class (NoMethodError) from randexp.rb:21