Skip to content

Instantly share code, notes, and snippets.

@alex-hladun
Created July 20, 2020 18:32
Show Gist options
  • Save alex-hladun/c0df28ad36414aab874dd57c42a15af7 to your computer and use it in GitHub Desktop.
Save alex-hladun/c0df28ad36414aab874dd57c42a15af7 to your computer and use it in GitHub Desktop.
Using attr_accessor to get and set instance variables.
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