Sha256: 24d1a3e23e3403c6c5e9d37003a52b3331431f4642e03bdfcc0c9717e49c3ba4

Contents?: true

Size: 1.38 KB

Versions: 100

Compression:

Stored size: 1.38 KB

Contents

class Module
  # Declares an attribute reader backed by an internally-named instance variable.
  def attr_internal_reader(*attrs)
    attrs.each {|attr_name| attr_internal_define(attr_name, :reader)}
  end

  # Declares an attribute writer backed by an internally-named instance variable.
  def attr_internal_writer(*attrs)
    attrs.each {|attr_name| attr_internal_define(attr_name, :writer)}
  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

    def attr_internal_define(attr_name, type)
      internal_name = attr_internal_ivar_name(attr_name).sub(/\A@/, '')
      # class_eval is necessary on 1.9 or else the methods are made private
      class_eval do
        # use native attr_* methods as they are faster on some Ruby implementations
        send("attr_#{type}", internal_name)
      end
      attr_name, internal_name = "#{attr_name}=", "#{internal_name}=" if type == :writer
      alias_method attr_name, internal_name
      remove_method internal_name
    end
end

Version data entries

100 entries across 95 versions & 12 rubygems

Version Path
activesupport-4.2.11.3 lib/active_support/core_ext/module/attr_internal.rb
activesupport-4.2.11.2 lib/active_support/core_ext/module/attr_internal.rb
cocoapods-dependency-html-0.0.2 vendor/bundle/gems/activesupport-4.2.11.1/lib/active_support/core_ext/module/attr_internal.rb
cocoapods-dependency-html-0.0.1 vendor/bundle/gems/activesupport-4.2.11.1/lib/active_support/core_ext/module/attr_internal.rb
activesupport-4.2.11.1 lib/active_support/core_ext/module/attr_internal.rb
activesupport-4.2.11 lib/active_support/core_ext/module/attr_internal.rb
activesupport-4.2.10 lib/active_support/core_ext/module/attr_internal.rb
activesupport-4.2.10.rc1 lib/active_support/core_ext/module/attr_internal.rb
activesupport-4.2.9 lib/active_support/core_ext/module/attr_internal.rb
activesupport-4.2.9.rc2 lib/active_support/core_ext/module/attr_internal.rb
activesupport-4.2.9.rc1 lib/active_support/core_ext/module/attr_internal.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/activesupport-4.2.8/lib/active_support/core_ext/module/attr_internal.rb
activesupport-4.2.8 lib/active_support/core_ext/module/attr_internal.rb
activesupport-4.2.8.rc1 lib/active_support/core_ext/module/attr_internal.rb
activesupport-4.2.7.1 lib/active_support/core_ext/module/attr_internal.rb
activesupport-4.2.7 lib/active_support/core_ext/module/attr_internal.rb
activesupport-4.1.16 lib/active_support/core_ext/module/attr_internal.rb
activesupport-4.1.16.rc1 lib/active_support/core_ext/module/attr_internal.rb
activesupport-4.2.7.rc1 lib/active_support/core_ext/module/attr_internal.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/core_ext/module/attr_internal.rb