Skip to content

Instantly share code, notes, and snippets.

@JuzerShakir
Created June 30, 2021 02:53
Show Gist options
  • Save JuzerShakir/4bbc34483ee3d1c6b42aa3c5b516b7b8 to your computer and use it in GitHub Desktop.
Save JuzerShakir/4bbc34483ee3d1c6b42aa3c5b516b7b8 to your computer and use it in GitHub Desktop.
Used in Variable doc in medium
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