Skip to content

Instantly share code, notes, and snippets.

@elomatreb
Created September 24, 2016 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elomatreb/4f1e25476b8e8d103b21bdef4fb3ce01 to your computer and use it in GitHub Desktop.
Save elomatreb/4f1e25476b8e8d103b21bdef4fb3ce01 to your computer and use it in GitHub Desktop.
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