Sha256: 87d4789899f8b4533bf850a28be7449b6e2b505a5b8a091979997dc5ea11617a

Contents?: true

Size: 955 Bytes

Versions: 5

Compression:

Stored size: 955 Bytes

Contents

class Module
  # Declares an attribute reader backed by an internally-named instance variable.
  def attr_internal_reader(*attrs)
    attrs.each do |attr|
      module_eval "def #{attr}() #{attr_internal_ivar_name(attr)} end"
    end
  end

  # Declares an attribute writer backed by an internally-named instance variable.
  def attr_internal_writer(*attrs)
    attrs.each do |attr|
      module_eval "def #{attr}=(v) #{attr_internal_ivar_name(attr)} = v end"
    end
  end

  # Declares an attribute reader and writer backed by an internally-named instance
  # variable.
  def attr_internal_accessor(*attrs)
    attr_internal_reader(*attrs)
    attr_internal_writer(*attrs)
  end

  alias_method :attr_internal, :attr_internal_accessor

  class << self; attr_accessor :attr_internal_naming_format end
  self.attr_internal_naming_format = '@_%s'

  private
    def attr_internal_ivar_name(attr)
      Module.attr_internal_naming_format % attr
    end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
activesupport-3.0.0.beta3 lib/active_support/core_ext/module/attr_internal.rb
activesupport-3.0.0.beta2 lib/active_support/core_ext/module/attr_internal.rb
activesupport-3.0.0.beta lib/active_support/core_ext/module/attr_internal.rb
activesupport-3.0.pre lib/active_support/core_ext/module/attr_internal.rb
recliner-0.0.1 vendor/activesupport/lib/active_support/core_ext/module/attr_internal.rb