Sha256: 6cb98e453ce7f5f392c19ec01e56401f5a62a5358cbecaed8b37367622eb19b4

Contents?: true

Size: 1.37 KB

Versions: 270

Compression:

Stored size: 1.37 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 do # class_eval is necessary on 1.9 or else the methods a made private
        # 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

270 entries across 226 versions & 25 rubygems

Version Path
font-awesome-rails-3.1.1.2 vendor/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/core_ext/module/attr_internal.rb
font-awesome-rails-3.1.1.2 vendor/ruby/2.0.0/gems/activesupport-3.2.12/lib/active_support/core_ext/module/attr_internal.rb
font-awesome-rails-3.1.1.1 vendor/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/core_ext/module/attr_internal.rb
font-awesome-rails-3.1.1.1 vendor/ruby/2.0.0/gems/activesupport-3.2.12/lib/active_support/core_ext/module/attr_internal.rb
font-awesome-rails-3.1.1.1 vendor/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/core_ext/module/attr_internal.rb
challah-1.0.0.beta3 vendor/bundle/gems/activesupport-3.2.13/lib/active_support/core_ext/module/attr_internal.rb
sidekiq-statsd-0.1.1 vendor/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/core_ext/module/attr_internal.rb
sidekiq-statsd-0.1.0 vendor/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/core_ext/module/attr_internal.rb
fc-webicons-0.0.4 vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/core_ext/module/attr_internal.rb
challah-1.0.0.beta2 vendor/bundle/gems/activesupport-3.2.13/lib/active_support/core_ext/module/attr_internal.rb
challah-1.0.0.beta vendor/bundle/gems/activesupport-3.2.11/lib/active_support/core_ext/module/attr_internal.rb
challah-1.0.0.beta vendor/bundle/gems/activesupport-3.2.13/lib/active_support/core_ext/module/attr_internal.rb
fc-webicons-0.0.3 vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/core_ext/module/attr_internal.rb
fc-webicons-0.0.2 vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/core_ext/module/attr_internal.rb
fc-webicons-0.0.1 vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/core_ext/module/attr_internal.rb
activesupport-3.2.13 lib/active_support/core_ext/module/attr_internal.rb
activesupport-3.1.12 lib/active_support/core_ext/module/attr_internal.rb
activesupport-3.2.13.rc2 lib/active_support/core_ext/module/attr_internal.rb
activesupport-3.2.13.rc1 lib/active_support/core_ext/module/attr_internal.rb
active_mailer-0.0.5 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.12/lib/active_support/core_ext/module/attr_internal.rb