Sha256: 357f17328fb2545d85a758d031e478085d61e2afe25efb8ec186df1416dfe3de

Contents?: true

Size: 1.09 KB

Versions: 19

Compression:

Stored size: 1.09 KB

Contents

# Copied from ActiveSupport because I couldn't get the ones in Facets to work...

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

        def #{sym}
          @@#{sym}
        end
      EOS
    end
  end
  alias_method :cattr_reader, :mattr_reader
  
  def mattr_writer(*syms)
    syms.each do |sym|
      class_eval(<<-EOS, __FILE__, __LINE__+1)
        unless defined? @@#{sym}
          @@#{sym} = nil
        end
        
        def self.#{sym}=(obj)
          @@#{sym} = obj
        end

        def #{sym}=(obj)
          @@#{sym} = obj
        end
      EOS
    end
  end
  alias_method :cattr_writer, :mattr_writer
  
  def mattr_accessor(*syms)
    mattr_reader(*syms)
    mattr_writer(*syms)
  end
  alias_method :cattr_accessor, :mattr_accessor
end

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
quality_extensions-1.4.0 lib/quality_extensions/module/attribute_accessors.rb
quality_extensions-1.3.2 lib/quality_extensions/module/attribute_accessors.rb
quality_extensions-1.3.1 lib/quality_extensions/module/attribute_accessors.rb
quality_extensions-1.3.0 lib/quality_extensions/module/attribute_accessors.rb
quality_extensions-1.1.6 lib/quality_extensions/module/attribute_accessors.rb
quality_extensions-1.1.1 lib/quality_extensions/module/attribute_accessors.rb
quality_extensions-0.1.1 lib/qualitysmith_extensions/module/attribute_accessors.rb
quality_extensions-1.0.3 lib/quality_extensions/module/attribute_accessors.rb
quality_extensions-1.0.0 lib/quality_extensions/module/attribute_accessors.rb
quality_extensions-0.1.2 lib/quality_extensions/module/attribute_accessors.rb
quality_extensions-0.1.4 lib/quality_extensions/module/attribute_accessors.rb
quality_extensions-1.1.0 lib/quality_extensions/module/attribute_accessors.rb
quality_extensions-1.1.2 lib/quality_extensions/module/attribute_accessors.rb
quality_extensions-1.1.3 lib/quality_extensions/module/attribute_accessors.rb
quality_extensions-1.1.4 lib/quality_extensions/module/attribute_accessors.rb
qualitysmith_extensions-0.0.49 lib/qualitysmith_extensions/module/attribute_accessors.rb
qualitysmith_extensions-0.0.60 lib/qualitysmith_extensions/module/attribute_accessors.rb
qualitysmith_extensions-0.0.63 lib/qualitysmith_extensions/module/attribute_accessors.rb
qualitysmith_extensions-0.0.64 lib/qualitysmith_extensions/module/attribute_accessors.rb