File: active_support/core_ext/module/attr_internal.rb

Overview
Module Structure
Class Hierarchy
Code

Overview

Module Structure

  module: <Toplevel Module>
  module: <Built-in Module>
  class: Module#1
includes
  Module ( ActiveSupport::CoreExtensions )
  ClassMethods ( ActiveSupport::Deprecation )
inherits from
  Object ( Builtin-Module )
has properties
method: attr_internal_reader / 1 #3
method: attr_internal_writer / 1 #10
method: attr_internal_accessor / 1 #18
method: attr_internal_ivar_name / 1 #29

Class Hierarchy

Object ( Builtin-Module )
  Module    #1

Code

   1  class Module
   2    # Declares an attribute reader backed by an internally-named instance variable.
   3    def attr_internal_reader(*attrs)
   4      attrs.each do |attr|
   5        module_eval "def #{attr}() #{attr_internal_ivar_name(attr)} end"
   6      end
   7    end
   8 
   9    # Declares an attribute writer backed by an internally-named instance variable.
  10    def attr_internal_writer(*attrs)
  11      attrs.each do |attr|
  12        module_eval "def #{attr}=(v) #{attr_internal_ivar_name(attr)} = v end"
  13      end
  14    end
  15 
  16    # Declares an attribute reader and writer backed by an internally-named instance
  17    # variable.
  18    def attr_internal_accessor(*attrs)
  19      attr_internal_reader(*attrs)
  20      attr_internal_writer(*attrs)
  21    end
  22 
  23    alias_method :attr_internal, :attr_internal_accessor
  24 
  25    private
  26      mattr_accessor :attr_internal_naming_format
  27      self.attr_internal_naming_format = '@_%s'
  28 
  29      def attr_internal_ivar_name(attr)
  30        attr_internal_naming_format % attr
  31      end
  32  end