Skip to content

Instantly share code, notes, and snippets.

@Whatapalaver
Last active July 19, 2018 11:04
Show Gist options
  • Save Whatapalaver/20fdeb2fe95615918b8f8af371fd7421 to your computer and use it in GitHub Desktop.
Save Whatapalaver/20fdeb2fe95615918b8f8af371fd7421 to your computer and use it in GitHub Desktop.
Attr_Reader || Attr_Writer || Attr_Accessor

If you write:

attr_writer :age

It is the equivalent of:

def age=(value)
  @age = value
end

Writing:

attr_reader :age

That gets translated into:

def age
  @age
end

Writing:

attr_accessor :age

Is translated to:

def age=(value)
  @age = value
end

and

def age
  @age
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment