Sha256: 1d227720e5fe4f9ae3319db0bfca0cac0fb0fe335fc5721acc8c3c8051e9179c

Contents?: true

Size: 763 Bytes

Versions: 2

Compression:

Stored size: 763 Bytes

Contents

module Woyo

module Attributes

  module ClassMethods

    def attributes *attrs
      @attributes ||= []                 # class instance variable in ClassMethods scope
      return @attributes if attrs.empty?
      @attributes = attrs                # todo: allow additions to existing attributes
      @attributes.each do |attr|
        class_eval("
          def #{attr}= arg
            attributes[:#{attr}] = @#{attr} = arg
          end
          def #{attr}(arg=nil)
            if arg.nil?
              @#{attr}
            else
              self.#{attr} = arg
            end
          end
        ")
      end
    end

  end 

  def self.included(base)
    base.extend(ClassMethods)
  end
  
  def attributes
    @attributes ||= {}
  end

end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
woyo-world-0.0.1 lib/woyo/world/attributes.rb
woyo-world-0.0.1.pre2 lib/woyo/world/attributes.rb