Skip to content

Instantly share code, notes, and snippets.

@yaodong
Created July 23, 2015 09:13
Show Gist options
  • Save yaodong/98c6758c967644d1b7c0 to your computer and use it in GitHub Desktop.
Save yaodong/98c6758c967644d1b7c0 to your computer and use it in GitHub Desktop.
class Person
attr_accessor :name
def set_name
@name = 'joe'
end
def dump_by_varibale
puts @name
end
def dump_by_reader
puts name
end
end
a = Person.new
a.set_name
a.dump_by_varibale #=> "joe"
a.dump_by_reader #=> "joe"
puts a.name #=> "joe"
# set by writer
a.name = "john"
a.dump_by_varibale #=> "john"
a.dump_by_reader #=> "john"
puts a.name #=> "john"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment