Class variable


1 Ruby[ | ]

class Dog
  @@count = 0
  def initialize
    @@count += 1
  end
  def self.get_count
    return @@count
  end
end
myDog1 = Dog.new
myDog2 = Dog.new
puts "dog count: #{Dog.get_count}"
# 2

2 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}