Last active
June 30, 2021 04:45
-
-
Save JuzerShakir/57551551f9444cc319bc68cb6a786c45 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 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