-
-
Save roktas/9954291 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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