Ruby 1.9では、次のようにクラス変数を使用できます。
class Sample
@@count = 0
def initialize
@@count += 1
end
def count
@@count
end
end
sample = Sample.new
puts sample.count # Output: 1
sample2 = Sample.new
puts sample2.count # Output: 2
Python 2.5以降で上記を実現するにはどうすればよいですか?