@@ -43,13 +43,15 @@ class Module
4343 #
4444 # module HairColors
4545 # mattr_reader :hair_colors, default: [:brown, :black, :blonde, :red]
46+ # mattr_reader(:hair_styles) { [:long, :short] }
4647 # end
4748 #
4849 # class Person
4950 # include HairColors
5051 # end
5152 #
5253 # Person.new.hair_colors # => [:brown, :black, :blonde, :red]
54+ # Person.new.hair_styles # => [:long, :short]
5355 def mattr_reader ( *syms , instance_reader : true , instance_accessor : true , default : nil , location : nil )
5456 raise TypeError , "module attributes should be defined directly on class, not singleton" if singleton_class?
5557 location ||= caller_locations ( 1 , 1 ) . first
@@ -107,13 +109,15 @@ def mattr_reader(*syms, instance_reader: true, instance_accessor: true, default:
107109 #
108110 # module HairColors
109111 # mattr_writer :hair_colors, default: [:brown, :black, :blonde, :red]
112+ # mattr_writer(:hair_styles) { [:long, :short] }
110113 # end
111114 #
112115 # class Person
113116 # include HairColors
114117 # end
115118 #
116119 # Person.class_variable_get("@@hair_colors") # => [:brown, :black, :blonde, :red]
120+ # Person.class_variable_get("@@hair_styles") # => [:long, :short]
117121 def mattr_writer ( *syms , instance_writer : true , instance_accessor : true , default : nil , location : nil )
118122 raise TypeError , "module attributes should be defined directly on class, not singleton" if singleton_class?
119123 location ||= caller_locations ( 1 , 1 ) . first
@@ -192,13 +196,15 @@ def mattr_writer(*syms, instance_writer: true, instance_accessor: true, default:
192196 #
193197 # module HairColors
194198 # mattr_accessor :hair_colors, default: [:brown, :black, :blonde, :red]
199+ # mattr_accessor(:hair_styles) { [:long, :short] }
195200 # end
196201 #
197202 # class Person
198203 # include HairColors
199204 # end
200205 #
201206 # Person.class_variable_get("@@hair_colors") # => [:brown, :black, :blonde, :red]
207+ # Person.class_variable_get("@@hair_styles") # => [:long, :short]
202208 def mattr_accessor ( *syms , instance_reader : true , instance_writer : true , instance_accessor : true , default : nil , &blk )
203209 location = caller_locations ( 1 , 1 ) . first
204210 mattr_reader ( *syms , instance_reader : instance_reader , instance_accessor : instance_accessor , default : default , location : location , &blk )
0 commit comments