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