Last active
July 8, 2021 02:53
-
-
Save JuzerShakir/7c0fca6800f45359faa9c58d77ab7b42 to your computer and use it in GitHub Desktop.
For variable doc 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
# global variable | |
$count = 0 | |
class Class_var | |
# will increase class variable count as soon as class is initiated | |
def initialize | |
$count += 1 | |
end | |
# we dont need this for global var | |
def output | |
$count | |
end | |
end | |
# initiate class | |
object = Class_var.new | |
object.output # => 1 | |
# initiate new object | |
new_object = Class_var.new | |
new_object.output # => 2 | |
# we can directly access like this | |
$count # => 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment