File: //usr/local/rvm/gems/default/doc/activesupport-6.1.4.1/ri/Module/mattr_accessor-i.ri
U:RDoc::AnyMethod[iI"mattr_accessor:ETI"Module#mattr_accessor;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I"EDefines both class and instance accessors for class attributes. ;TI"DAll class and instance methods created will be public, even if ;TI"Gthis method is called with a private or protected access modifier.;To:RDoc::Markup::BlankLine o:RDoc::Markup::Verbatim; [I"module HairColors
;TI"# mattr_accessor :hair_colors
;TI" end
;TI"
;TI"class Person
;TI" include HairColors
;TI" end
;TI"
;TI">HairColors.hair_colors = [:brown, :black, :blonde, :red]
;TI"AHairColors.hair_colors # => [:brown, :black, :blonde, :red]
;TI"APerson.new.hair_colors # => [:brown, :black, :blonde, :red]
;T:@format0o;
; [I"OIf a subclass changes the value then that would also change the value for ;TI"Oparent class. Similarly if parent class changes the value then that would ;TI"(change the value of subclasses too.;T@o;; [
I"class Citizen < Person
;TI" end
;TI"
;TI"&Citizen.new.hair_colors << :blue
;TI"HPerson.new.hair_colors # => [:brown, :black, :blonde, :red, :blue]
;T;
0o;
; [I"OTo omit the instance writer method, pass <tt>instance_writer: false</tt>. ;TI"NTo omit the instance reader method, pass <tt>instance_reader: false</tt>.;T@o;; [I"module HairColors
;TI"S mattr_accessor :hair_colors, instance_writer: false, instance_reader: false
;TI" end
;TI"
;TI"class Person
;TI" include HairColors
;TI" end
;TI"
;TI";Person.new.hair_colors = [:brown] # => NoMethodError
;TI";Person.new.hair_colors # => NoMethodError
;T;
0o;
; [I"NOr pass <tt>instance_accessor: false</tt>, to omit both instance methods.;T@o;; [I"module HairColors
;TI"= mattr_accessor :hair_colors, instance_accessor: false
;TI" end
;TI"
;TI"class Person
;TI" include HairColors
;TI" end
;TI"
;TI";Person.new.hair_colors = [:brown] # => NoMethodError
;TI";Person.new.hair_colors # => NoMethodError
;T;
0o;
; [I"3You can set a default value for the attribute.;T@o;; [I"module HairColors
;TI"M mattr_accessor :hair_colors, default: [:brown, :black, :blonde, :red]
;TI" end
;TI"
;TI"class Person
;TI" include HairColors
;TI" end
;TI"
;TI"TPerson.class_variable_get("@@hair_colors") # => [:brown, :black, :blonde, :red];T;
0:
@fileI">lib/active_support/core_ext/module/attribute_accessors.rb;T:0@omit_headings_from_table_of_contents_below000[[I"cattr_accessor;To;; [ ;@W;0I"g(*syms, instance_reader: true, instance_writer: true, instance_accessor: true, default: nil, &blk);T@WFI"Module;TcRDoc::NormalClass00