Skip to content

Instantly share code, notes, and snippets.

@JuzerShakir
Last active June 30, 2021 04:45
Show Gist options
  • Save JuzerShakir/57551551f9444cc319bc68cb6a786c45 to your computer and use it in GitHub Desktop.
Save JuzerShakir/57551551f9444cc319bc68cb6a786c45 to your computer and use it in GitHub Desktop.
Used in Variable doc in medium
class Inst_var
# will initialize instance variable when class is initiated
def initialize
@count = 0
end
# add up
def add_count
@count += 1
end
def output
@count
end
end
# initiate class
object = Inst_var.new
# original instance variable value
object.output # => 0
# updates original variable value
object.add_count
# new output
object.output # => 1
# initiate new object
new_object = Inst_var.new
# back to original instance variable value
new_object.output # => 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment