Sha256: ac6fcca572b62410ed175c90c109f0411b0ca9ec79c8eaf383929944675dba03

Contents?: true

Size: 887 Bytes

Versions: 11

Compression:

Stored size: 887 Bytes

Contents

# Extends the class object with class and instance accessors for class attributes,
# just like the native attr* accessors for instance attributes.
class Class # :nodoc:
  def cattr_reader(*syms)
    syms.flatten.each do |sym|
      class_eval(<<-EOS, __FILE__, __LINE__)
        unless defined? @@#{sym}
          @@#{sym} = nil
        end

        def self.#{sym}
          @@#{sym}
        end

        def #{sym}
          @@#{sym}
        end
      EOS
    end
  end

  def cattr_writer(*syms)
    syms.flatten.each do |sym|
      class_eval(<<-EOS, __FILE__, __LINE__)
        unless defined? @@#{sym}
          @@#{sym} = nil
        end

        def self.#{sym}=(obj)
          @@#{sym} = obj
        end

        def #{sym}=(obj)
          @@#{sym} = obj
        end
      EOS
    end
  end

  def cattr_accessor(*syms)
    cattr_reader(*syms)
    cattr_writer(*syms)
  end
end

Version data entries

11 entries across 11 versions & 4 rubygems

Version Path
activesupport-1.3.1 lib/active_support/core_ext/class/attribute_accessors.rb
activesupport-1.4.0 lib/active_support/core_ext/class/attribute_accessors.rb
activesupport-1.3.0 lib/active_support/core_ext/class/attribute_accessors.rb
monetra-ruby-0.0.6 lib/monetra/active_support/core_ext/class/attribute_accessors.rb
shattered-0.7.0 lib/shattered_support/core_ext/class/attribute_accessors.rb
shattered_support-0.5.0.2 lib/shattered_support/core_ext/class/attribute_accessors.rb
shattered_support-0.5.1 lib/shattered_support/core_ext/class/attribute_accessors.rb
shattered_support-0.5.0.1 lib/shattered_support/core_ext/class/attribute_accessors.rb
shattered_support-0.3.3 lib/shattered_support/core_ext/class/attribute_accessors.rb
shattered_support-0.4 lib/shattered_support/core_ext/class/attribute_accessors.rb
shattered_support-0.4.0.1 lib/shattered_support/core_ext/class/attribute_accessors.rb