Method: Module#mattr_accessor

Defined in:
lib/core/facets/module/mattr.rb

#mattr_accessor(*syms) ⇒ Object

Creates a class-variable attr_accessor that can be accessed both on an instance and class level.

c = Class.new do
  mattr_accessor :a
end

c.a = 10
c.a           #=> 10

x = c.new
x.a           #=> 10

NOTE: This methiod is not a common core extension and is not loaded automatically when using require 'facets'.

CREDIT: David Heinemeier Hansson

Uncommon:

  • require ‘facets/module/cattr’



275
276
277
# File 'lib/core/facets/module/mattr.rb', line 275

def mattr_accessor(*syms)
  mattr_reader(*syms) + mattr_writer(*syms)
end