<commit_before>
# A module describes the capabilities of a group of objects, ie what data it has
# and functions it responds to.
# The group may be a Class, but a module may be included into classes and objects too.
#
# The class also keeps a list of class methods (with names+code)
# Class methods are instance methods on the class object

# So it is essential that the class (the object defining the class)
# can carry methods. It does so as instance variables.
# In fact this property is implemented in the Object, as methods
# may be added to any object at run-time

module Parfait
  class Module < Object
    def initialize name , superclass
      super()
      @name = name
      @instance_methods = []
      @name = name
      @super_class = superclass
      @meta_class = Virtual::MetaClass.new(self)
    end

    def name
      @name
    end

    def instance_methods
      @instance_methods
    end

    def add_instance_method method
      raise "not a method #{method.class} #{method.inspect}" unless method.is_a? Method
      raise "syserr #{method.name.class}" unless method.name.is_a? Word
      @instance_methods << method
      #puts "#{self.name} add #{method.name}"
      method
    end

    def create_instance_method  name , arg_names
      clazz = Space.object_space.get_class_by_name(self.name)
      raise "??? #{self.name}" unless clazz
      Method.new_object( clazz , name , arg_names )
    end

    # this needs to be done during booting as we can't have all the classes and superclassses
    # instantiated. By that logic it should maybe be part of vm rather.
    # On the other hand vague plans to load the hierachy from sof exist, so for now...
    def set_super_class sup
      @super_class = sup
    end

    def get_instance_method fname
      raise "uups #{fname}.#{fname.class}" unless fname.is_a?(Word) or fname.is_a?(String)
      @instance_methods.detect{ |fun| fun.name == fname }
    end

    # get the method and if not found, try superclasses. raise error if not found
    def resolve_method m_name
      raise "uups #{m_name}.#{m_name.class}" unless m_name.is_a? Word
      method = get_instance_method(m_name)<commit_msg>fix method list (was still array)<commit_after>
# A module describes the capabilities of a group of objects, ie what data it has
# and functions it responds to.
# The group may be a Class, but a module may be included into classes and objects too.
#
# The class also keeps a list of class methods (with names+code)
# Class methods are instance methods on the class object

# So it is essential that the class (the object defining the class)
# can carry methods. It does so as instance variables.
# In fact this property is implemented in the Object, as methods
# may be added to any object at run-time

module Parfait
  class Module < Object
    def initialize name , superclass
      super()
      @name = name
      @instance_methods = List.new_object
      @name = name
      @super_class = superclass
      @meta_class = Virtual::MetaClass.new(self)
    end

    def name
      @name
    end

    def instance_methods
      @instance_methods
    end

    def add_instance_method method
      raise "not a method #{method.class} #{method.inspect}" unless method.is_a? Method
      raise "syserr #{method.name.class}" unless method.name.is_a? Word
      found = get_instance_method( method.name )
      if found
        @instance_methods.delete(found)
        raise "existed in #{self.name} #{Sof::Writer.write found.info.blocks}"
      end
      @instance_methods.push method
      #puts "#{self.name} add #{method.name}"
      method
    end

    def create_instance_method  name , arg_names
      clazz = Space.object_space.get_class_by_name(self.name)
      raise "??? #{self.name}" unless clazz
      Method.new_object( clazz , name , arg_names )
    end

    # this needs to be done during booting as we can't have all the classes and superclassses
    # instantiated. By that logic it should maybe be part of vm rather.
    # On the other hand vague plans to load the hierachy from sof exist, so for now...
    def set_super_class sup
      @super_class = sup
    end

    def get_instance_method fname
      raise "uups #{fname}.#{fname.class}" unless fname.is_a?(Word) or fname.is_a?(String)
      #if we had a hash this would be easier.  Detect or find would help too
      @instance_methods.each do |m|
        return m if(m.name == fname )
      end
      nil
    end

    # get the method and if not found, try superclasses. raise error if not found
    def resolve_method m_name
      raise "uups #{m_name}.#{m_name.class}" unless m_name.is_a? Word
      method = get_instance_method(m_name)
{'fraction_non_alphanumeric': 0.0748983522362508, 'fraction_numerical': 0.0, 'mean_word_length': 2.9409780775716694, 'pattern_counts': {'":': 0, '<': 7, '<?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': '5071556', 'n_tokens_mistral': 1370, 'n_tokens_neox': 1349, 'n_words': 552}