Module: Arel::ClassExtensions

Defined in:
lib/arel/algebra/core_extensions/class.rb

Instance Method Summary collapse

Instance Method Details

#attributes(*attrs) ⇒ Object



3
4
5
6
# File 'lib/arel/algebra/core_extensions/class.rb', line 3

def attributes(*attrs)
  @attributes = attrs
  attr_reader(*attrs)
end

#derive(method_name) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/arel/algebra/core_extensions/class.rb', line 12

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

#deriving(*methods) ⇒ Object



8
9
10
# File 'lib/arel/algebra/core_extensions/class.rb', line 8

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