Skip to content

Instantly share code, notes, and snippets.

@JuzerShakir
Last active July 8, 2021 02:53
Show Gist options
  • Save JuzerShakir/7c0fca6800f45359faa9c58d77ab7b42 to your computer and use it in GitHub Desktop.
Save JuzerShakir/7c0fca6800f45359faa9c58d77ab7b42 to your computer and use it in GitHub Desktop.
For variable doc medium
# 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