-
-
Save elomatreb/4f1e25476b8e8d103b21bdef4fb3ce01 to your computer and use it in GitHub Desktop.
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 Person | |
attr_accessor :name | |
def something | |
puts "The current value of the instance variable is:" | |
p @name | |
end | |
end | |
p = Person.new # Create a new instance of the Person class | |
p.something | |
# prints: | |
#=> The current value of the instance variable is: | |
#=> nil | |
p.name = "Mark" # Use the method `name=` to assign something | |
p.something | |
# prints: | |
#=> The current value of the instance variable is: | |
#=> "Mark" | |
# Use the method `name` to read the value | |
puts p.name | |
# prints: | |
#=> Mark |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment