Hi,

Let me hear your opinions, composition or module.

Composition:

  class Representation
    def to_string(obj)
      return sprintf('%s=%s', obj.class, obj.value)
    end
  end

  class Domain
    def initialize
      @value = 10
    end
    attr_reader :value
  
    def to_s
      Representation.new.to_string(self)
    end
  end

  puts(Domain.new)

or Module:

  module Representation
    def to_s
      return sprintf('%s=%s', self.class, @value)
    end
  end

  class Domain
    include Representation
  
    def initialize
      @value = 10
    end
  end

  puts(Domain.new)

greentea / fa2.so-net.ne.jp