Skip to content

Instantly share code, notes, and snippets.

@SamGerber-zz
Created December 9, 2015 06:54
Show Gist options
  • Save SamGerber-zz/6dbdcfcac1a30b41f205 to your computer and use it in GitHub Desktop.
Save SamGerber-zz/6dbdcfcac1a30b41f205 to your computer and use it in GitHub Desktop.
Getting and Setting Instance Variables Using an Attribute Accessor
class Universe
attr_accessor :answer
def initialize
@answer = "42"
end
end
universe = Universe.new # => #<Universe:0x007f63e303e848 @answer="42">
universe.answer # => "42"
universe.answer="Tricky" # => "Tricky"
universe.answer # => "Tricky"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment