<p>I couldn't really find this in Rails documentation but it seems like <strong>'mattr_accessor'</strong> is the <strong>Module</strong> corollary for <strong>'attr_accessor'</strong> (getter &amp; setter) in a normal Ruby <strong>class</strong>.</p>

<p>Eg. in a class</p>

<pre><code>class User
  attr_accessor :name

  def set_fullname
    @name = "#{self.first_name} #{self.last_name}"
  end
end
</code></pre>

<p>Eg. in a module</p>

<pre><code>module Authentication
  mattr_accessor :current_user

  def login
    @current_user = session[:user_id] || nil
  end
end
</code></pre>

<p>This helper method is provided by <strong>ActiveSupport</strong>.</p>

Rails extends Ruby with both
```
mattr_accessor
```
(Module accessor) and
```
cattr_accessor
```
(as well as _
```
reader
```
/
```
_writer
```
versions).  As Ruby's
```
attr_accessor
```
generates getter/setter methods for
instances
,
```
cattr/mattr_accessor
```
provide getter/setter methods at the
class
or
module
level.  Thus:
```
```
module Config
  mattr_accessor :hostname
  mattr_accessor :admin_email
end
```
```
is short for:
```
```
module Config
  def self.hostname
    @hostname
  end
  def self.hostname=(hostname)
    @hostname = hostname
  end
  def self.admin_email
    @admin_email
  end
  def self.admin_email=(admin_email)
    @admin_email = admin_email
  end
end
```
```
Both versions allow you to access the module-level variables like so:
```
```
>> Config.hostname = "example.com"
>> Config.admin_email = "admin@example.com"
>> Config.hostname # => "example.com"
>> Config.admin_email # => "admin@example.com"
```
```