<commit_before>require 'forwardable'

module Hamster

  module Immutable

    def self.included(klass)
      klass.extend(ClassMethods)
      klass.instance_eval do
        include InstanceMethods
      end
    end

    module ClassMethods

      def new(*args)
        super.freeze
      end

    end

    module InstanceMethods

      extend Forwardable

      def immutable?
        frozen?
      end

      alias_method :__hamster_dup__, :dup
      private :__hamster_dup__

      def dup
        self
      end
      def_delegator :self, :dup, :clone

      protected

      def transform_unless(condition, &block)
        condition ? self : transform(&block)
      end

      def transform(&block)
        __hamster_dup__.tap { |copy| copy.instance_eval(&block) }.freeze
      end

    end

  end

end<commit_msg>Forwardable is a lot of infrastructure for not a lot of benefit.<commit_after>module Hamster

  module Immutable

    def self.included(klass)
      klass.extend(ClassMethods)
      klass.instance_eval do
        include InstanceMethods
      end
    end

    module ClassMethods

      def new(*args)
        super.freeze
      end

    end

    module InstanceMethods

      def immutable?
        frozen?
      end

      alias_method :__hamster_dup__, :dup
      private :__hamster_dup__

      def dup
        self
      end

      def clone
        self
      end

      protected

      def transform_unless(condition, &block)
        condition ? self : transform(&block)
      end

      def transform(&block)
        __hamster_dup__.tap { |copy| copy.instance_eval(&block) }.freeze
      end

    end

  end

end
{'fraction_non_alphanumeric': 0.05609756097560976, 'fraction_numerical': 0.0, 'mean_word_length': 1.9408602150537635, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '205160', 'n_tokens_mistral': 488, 'n_tokens_neox': 463, 'n_words': 128}