Class variable

Jmnote (토론 | 기여)님의 2014년 6월 3일 (화) 21:32 판 (새 문서: ==Ruby== category: Ruby <source lang='Ruby'> class Dog @@count = 0 def initialize @@count += 1 end def self.get_count return @@count end end myDog1 = Dog.new m...)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)


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 }}