Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

attr

khmp

Sponsor

They act as markers that create an expanded method:

attr_accessor will create a method to read and write a variable.
attr_writer will create a method to only write a variable.
attr_reader will create a method to only read a variable.

Code:
attr_accessor :sweet
Will get interpreted as:
Code:
def sweet=(sweet)
  @sweet = sweet
end

def sweet
  return @sweet
end

Code:
attr_writer :sweet
Will get interpreted as:
Code:
def sweet=(sweet)
  @sweet = sweet
end

Code:
attr_reader :sweet
Will get interpreted as:
Code:
def sweet
  return @sweet
end

They are basically time savers rather than having to create accessor methods for every instance variable of a class you would want to access.

Good luck with it AbyssalLord! :thumb:
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top