Sha256: cc6eec72e391a983ac523548169767d4e364523cb533cfbdd8c596dc634e85b3

Contents?: true

Size: 739 Bytes

Versions: 3

Compression:

Stored size: 739 Bytes

Contents

module ZTK::DSL::Core

  # @author Zachary Patten <zachary AT jovelabs DOT com>
  # @api private
  module Attributes

    def self.included(base)
      base.class_eval do
        base.send(:extend, ZTK::DSL::Core::Attributes::ClassMethods)
      end
    end

    def attributes
      @attributes ||= {}
    end

    # @author Zachary Patten <zachary AT jovelabs DOT com>
    module ClassMethods

      def attribute(key, options={})
        send(:define_method, key) do |*args|
          if args.count == 0
            attributes[key]
          else
            send("#{key}=", *args)
          end
        end

        send(:define_method, "#{key}=") do |value|
          attributes[key] = value
        end
      end

    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ztk-1.4.7 lib/ztk/dsl/core/attributes.rb
ztk-1.4.6 lib/ztk/dsl/core/attributes.rb
ztk-1.4.5 lib/ztk/dsl/core/attributes.rb