<commit_before>module Atomy
  NAMESPACES = {}

  class Namespace
    attr_reader :name, :using, :symbols

    def initialize(name, using = [])
      using = [:atomy] + using unless name == :atomy

      @name = name
      @using = using
      @symbols = []
    end

    def register(sym)
      @symbols << sym unless contains?(sym)
    end

    def contains?(sym)
      @symbols.include?(sym)
    end

    def use(sym)
      @using << sym unless @using.include?(sym)
    end

    def resolve(sym)
      return @name if contains?(sym)

      @using.each do |ns|
        return ns if Namespace.get(ns).contains?(sym)
      end

      nil
    end

    def self.ensure(name, using = [])
      Thread.current[:atomy_namespace] =
        NAMESPACES[name.to_sym] ||=
          new(name, using)
    end

    def self.get(name = nil)
      return NAMESPACES[name.to_sym] if name
      Thread.current[:atomy_namespace]
    end

    def self.set(x)
      Thread.current[:atomy_namespace] = x
    end

    def self.register(sym, name = nil)
      ns = get(name)
      return unless ns
      ns.register(sym)
    end

    def self.name
      ns = get
      return unless ns
      ns.name
    end
  end
end

def Rubinius.bind_call(recv, nmeth, *args, &blk)
  # TODO: foo/bar/baz should be foo/bar, baz
  # TODO: allow_private stuff
  ns_name, meth_name = nmeth.to_s.split("/")
  ns_name, meth_name = meth_name, ns_name unless meth_name

  if ns_name == "_"
    ns = nil
  else 
    ns = Atomy::Namespace.get(!ns_name ? nil : ns_name.to_sym)
  end

  meth = meth_name.to_sym

  res = Rubinius::CallUnit.send_as(meth)

  if ns
    ([ns.name] + ns.using).reverse_each do |u|
      n = (u.to_s + "/" + meth.to_s).to_sym
      res = Rubinius::CallUnit.test(
        Rubinius::CallUnit.test_respond_to(n),
        Rubinius::CallUnit.send_as(n),
        res
      )
    end
  end

  res
end
<commit_msg>only attempt calling a namespaced method if the namespace contains it, and recurse into each namespace's used namespaces<commit_after>module Atomy
  NAMESPACES = {}

  class Namespace
    attr_reader :name, :using, :symbols

    def initialize(name, using = [])
      using = [:atomy] + using unless name == :atomy

      @name = name
      @using = using
      @symbols = []
    end

    def register(sym)
      @symbols << sym unless contains?(sym)
    end

    def contains?(sym)
      @symbols.include?(sym)
    end

    def use(sym)
      @using << sym unless @using.include?(sym)
    end

    def resolve(sym)
      return @name if contains?(sym)

      @using.each do |ns|
        return ns if Namespace.get(ns).contains?(sym)
      end

      nil
    end

    def self.ensure(name, using = [])
      Thread.current[:atomy_namespace] =
        NAMESPACES[name.to_sym] ||=
          new(name, using)
    end

    def self.get(name = nil)
      return NAMESPACES[name.to_sym] if name
      Thread.current[:atomy_namespace]
    end

    def self.set(x)
      Thread.current[:atomy_namespace] = x
    end

    def self.register(sym, name = nil)
      ns = get(name)
      return unless ns
      ns.register(sym)
    end

    def self.name
      ns = get
      return unless ns
      ns.name
    end
  end
end

def Rubinius.bind_call(recv, nmeth, *args, &blk)
  # TODO: foo/bar/baz should be foo/bar, baz
  # TODO: allow_private stuff
  ns_name, meth_name = nmeth.to_s.split("/")
  ns_name, meth_name = meth_name, ns_name unless meth_name

  if ns_name == "_"
    ns = nil
  else 
    ns = Atomy::Namespace.get(!ns_name ? nil : ns_name.to_sym)
  end

  meth = meth_name.to_sym

  res = Rubinius::CallUnit.send_as(meth)

  if ns
    nss = [ns]
    scan = proc do |u|
      unless un = Atomy::Namespace.get(u) and \
              !nss.include?(un)
        next
      end

      nss << un
      un.using.each(&scan)
    end

    ns.using.each(&scan)

    nss.reverse_each do |n|
      next unless n.contains?(meth)
      m = (n.name.to_s + "/" + meth.to_s).to_sym
      res = Rubinius::CallUnit.test(
        Rubinius::CallUnit.test_respond_to(m),
        Rubinius::CallUnit.send_as(m),
        res
      )
    end
  end

  res
end

{'fraction_non_alphanumeric': 0.11427182105519086, 'fraction_numerical': 0.0, 'mean_word_length': 2.209048361934477, 'pattern_counts': {'":': 0, '<': 13, '<?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': '1598949', 'n_tokens_mistral': 1489, 'n_tokens_neox': 1433, 'n_words': 351}