Created
July 20, 2020 18:32
-
-
Save alex-hladun/c0df28ad36414aab874dd57c42a15af7 to your computer and use it in GitHub Desktop.
Using attr_accessor to get and set instance variables.
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 initialize(name) | |
@name = name | |
end | |
end | |
p = Person.new('L. Ron') | |
puts p.name | |
p.name = 'Alex' | |
puts p.name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment