Skip to content

Instantly share code, notes, and snippets.

@roktas
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roktas/9954291 to your computer and use it in GitHub Desktop.
Save roktas/9954291 to your computer and use it in GitHub Desktop.
# encoding: utf-8
class A
attr :x
@count = 0
def initialize(verilen)
@x = verilen
A.count += 1
end
class << self
attr_accessor :count
end
end
class B < A
# B sınıfından nesne üretildiğinde sayaç artmasın
def initialize(verilen)
@x = verilen
end
end
a1 = A.new 203
puts "Kaç tane A nesnesi? #{A.count}"
b1 = B.new 20
b2 = B.new 2
a2 = A.new 12
puts "Kaç tane A nesnesi? #{A.count}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment