Created
June 30, 2021 02:53
-
-
Save JuzerShakir/4bbc34483ee3d1c6b42aa3c5b516b7b8 to your computer and use it in GitHub Desktop.
Used in Variable doc in medium
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
class Class_var | |
# class variable | |
@@count = 0 | |
# will increase class variable count as soon as class is initiated | |
def initialize | |
@@count += 1 | |
end | |
def output | |
@@count | |
end | |
end | |
# initiate class | |
object = Class_var.new | |
object.output # => 1 | |
# initiate new object | |
new_object = Class_var.new | |
# class varaible doesnt reset the value.. | |
# ..it remembers and carries on its value to other objects | |
new_object.output # => 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment