Sha256: d8d4260049f681721c9e2601b40e62cecdf807e30f5f74eb3ecb0c273367c048

Contents?: true

Size: 711 Bytes

Versions: 10

Compression:

Stored size: 711 Bytes

Contents

module Arel
  module ClassExtensions
    def attributes(*attrs)
      @attributes = attrs
      attr_reader(*attrs)
    end

    def deriving(*methods)
      methods.each { |m| derive m }
    end

    def derive(method_name)
      methods = {
        :initialize => "
          def #{method_name}(#{@attributes.join(',')})
            #{@attributes.collect { |a| "@#{a} = #{a}" }.join("\n")}
          end
        ",
        :== => "
          def ==(other)
            #{name} === other &&
            #{@attributes.collect { |a| "@#{a} == other.#{a}" }.join(" &&\n")}
          end
        "
      }
      class_eval methods[method_name], __FILE__, __LINE__
    end

    Class.send(:include, self)
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
arel-compat-0.4.0 lib/arel/algebra/core_extensions/class.rb
arel-0.4.0 lib/arel/algebra/core_extensions/class.rb
arel-0.3.3 lib/arel/algebra/core_extensions/class.rb
arel-0.3.2 lib/arel/algebra/core_extensions/class.rb
arel-0.3.1 lib/arel/algebra/core_extensions/class.rb
arel-0.3.0 lib/arel/algebra/core_extensions/class.rb
arel-0.2.1 lib/arel/algebra/core_extensions/class.rb
arel-0.2.0 lib/arel/algebra/core_extensions/class.rb
arel-0.2.pre lib/arel/algebra/core_extensions/class.rb
arel-0.1.2 lib/arel/algebra/core_extensions/class.rb