Sha256: 056157921483b137b6b9ac3a541bb7be9d48fd53abd8148d028883f877386bcf

Contents?: true

Size: 662 Bytes

Versions: 13

Compression:

Stored size: 662 Bytes

Contents

module Cranium::AttributeDSL

  def define_attribute(name)
    class_eval <<-attribute_method

      def #{name}(*args)
        return @#{name} if args.count.zero?

        @#{name} = args.first
      end

    attribute_method
  end



  def define_array_attribute(name)
    class_eval <<-attribute_method

      def #{name}(*args)
        return @#{name} || [] if args.count.zero?

        @#{name} = args
      end

    attribute_method
  end



  def define_boolean_attribute(name)
    class_eval <<-attribute_method

      def #{name}(*args)
        return !!@#{name} if args.count.zero?

        @#{name} = !!args
      end

    attribute_method
  end

end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
cranium-0.8.1 lib/cranium/attribute_dsl.rb
cranium-0.8 lib/cranium/attribute_dsl.rb
cranium-0.7 lib/cranium/attribute_dsl.rb
cranium-0.6.1 lib/cranium/attribute_dsl.rb
cranium-0.5 lib/cranium/attribute_dsl.rb
cranium-0.4.3 lib/cranium/attribute_dsl.rb
cranium-0.4.2 lib/cranium/attribute_dsl.rb
cranium-0.4.1 lib/cranium/attribute_dsl.rb
cranium-0.4 lib/cranium/attribute_dsl.rb
cranium-0.3.1 lib/cranium/attribute_dsl.rb
cranium-0.3.0 lib/cranium/attribute_dsl.rb
cranium-0.2.1 lib/cranium/attribute_dsl.rb
cranium-0.2.0 lib/cranium/attribute_dsl.rb