Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: bf0d548ad3
Fetching contributors…

Cannot retrieve contributors at this time

file 41 lines (36 sloc) 0.902 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
module Archive

  module EasyClassMaker

    def self.included(base)
      base.extend(ClassMethods)
    end

    module ClassMethods
      # creates the attributes class variable and creates each attribute's accessor methods
      def attributes(*attrs)
        @@attributes = attrs
        @@attributes.each { |a| attr_accessor a }
      end

      # read method for attributes class variable
      def self.attributes; @@attributes end
    end

    # allows for any class that includes this to use a block to initialize
    # variables instead of assigning each one seperately
    #
    # Example:
    #
    # instead of...
    #
    # a = Archive.new
    # a.foo = 'thing'
    # a.bar = 'another thing'
    #
    # you can ...
    #
    # Archive.new do |a|
    # a.foo = 'thing'
    # a.bar = 'another thing'
    # end
    def initialize
      yield self if block_given?
    end
  end
end
Something went wrong with that request. Please try again.