class Unparser::Concord

Original code before vendoring and reduction from: github.com/mbj/concord.
A mixin to define a composition

def define_equalizer

Other tags:
    Api: - private

Returns:
  • (undefined) -
def define_equalizer
  include(Equalizer.new(*names))
end

def define_initialize

Other tags:
    Api: - private

Returns:
  • (undefined) -
def define_initialize
  ivars = instance_variable_names
  size = names.size
  define_method :initialize do |*args|
    args_size = args.size
    unless args_size.equal?(size)
      fail ArgumentError, "wrong number of arguments (#{args_size} for #{size})"
    end
    ivars.zip(args) { |ivar, arg| instance_variable_set(ivar, arg) }
  end
end

def define_readers

Other tags:
    Api: - private

Returns:
  • (undefined) -
def define_readers
  attribute_names = names
  attr_reader(*attribute_names)
  protected(*attribute_names) if attribute_names.any?
end

def initialize(*names)

Other tags:
    Api: - private

Returns:
  • (undefined) -
def initialize(*names)
  if names.length > MAX_NR_OF_OBJECTS
    fail "Composition of more than #{MAX_NR_OF_OBJECTS} objects is not allowed"
  end
  @names = names
  define_initialize
  define_readers
  define_equalizer
end

def instance_variable_names

Other tags:
    Api: - private

Returns:
  • (String) -
def instance_variable_names
  names.map { |name| "@#{name}" }
end