Calling the attr_accessor method does the same job as calling both attr_reader and attr_writer together, for one or more instance methods : attr_reader « Class « Ruby






Calling the attr_accessor method does the same job as calling both attr_reader and attr_writer together, for one or more instance methods


#!/usr/bin/env ruby

class Gaits
  attr_accessor :walk, :trot, :canter
end

Gaits.instance_methods.sort - Object.instance_methods 

 








Related examples in the same category

1.attr_reader creates one or more instance variables, with corresponding methods that return (get) the values of each method.
2.Use attr_reader to add a new attribute and use initialize method to set it
3.attr_reader creates these accessor methods for you.