<commit_before>module Kernel
  def method_missing(symbol, *args, &block)
    raise NoMethodError.new("undefined method `#{symbol}' for #{inspect}", symbol, args)
  end

  def =~(obj)
    false
  end

  def !~(obj)
    not(self =~ obj)
  end

  def ===(other)
    self.object_id == other.object_id || self == other
  end

  def <=>(other)
    %x{
      // set guard for infinite recursion
      self.$$comparable = true;

      var x = #{self == other};

      if (x && x !== nil) {
        return 0;
      }

      return nil;
    }
  end

  def method(name)
    %x{
      var meth = self['$' + name];

      if (!meth || meth.$$stub) {
        #{raise NameError.new("undefined method `#{name}' for class `#{self.class}'", name)};
      }

      return #{Method.new(self, `meth.$$owner || #{self.class}`, `meth`, name)};
    }
  end

  def methods(all = true)
    %x{
      var methods = [];

      for (var key in self) {
        if (key[0] == "$" && typeof(self[key]) === "function") {
          if (all == false || all === nil) {
            if (!Opal.hasOwnProperty.call(self, key)) {
              continue;
            }
          }
          if (self[key].$$stub === undefined) {
            methods.push(key.substr(1));
          }
        }
      }

      return methods;
    }
  end

  alias public_methods methods

  def Array(object)
    %x{
      var coerced;

      if (object === nil) {
        return [];
      }

      if (object.$$is_array) {
        return object;
      }

      coerced = #{Opal.coerce_to?(object, Array, :to_ary)};
      if (coerced !== nil) { return coerced; }

      coerced = #{Opal.coerce_to?(object, Array, :to_a)};
      if (coerced !== nil) { return coerced; }

      return [object];
    }
  end

  def at_exit(&block)
    $__at_exit__ ||= []
    $__at_exit__ << block
  end

  # Opal does not support #caller, but we stub it as an empty array to not
  # break dependant libs
  def caller(*args)
    []
  end

  def class
    `self.$$class`
  end

  def copy_instance_variables(other)
    %x{
      for (var name in other) {
        if (other.hasOwnProperty(name) && name.charAt(0) !== '$') {
          self[name] = other[name];
        }
      }
    }
  end
<commit_msg>Prefer Object.keys/for over for/in (performance)<commit_after>module Kernel
  def method_missing(symbol, *args, &block)
    raise NoMethodError.new("undefined method `#{symbol}' for #{inspect}", symbol, args)
  end

  def =~(obj)
    false
  end

  def !~(obj)
    not(self =~ obj)
  end

  def ===(other)
    self.object_id == other.object_id || self == other
  end

  def <=>(other)
    %x{
      // set guard for infinite recursion
      self.$$comparable = true;

      var x = #{self == other};

      if (x && x !== nil) {
        return 0;
      }

      return nil;
    }
  end

  def method(name)
    %x{
      var meth = self['$' + name];

      if (!meth || meth.$$stub) {
        #{raise NameError.new("undefined method `#{name}' for class `#{self.class}'", name)};
      }

      return #{Method.new(self, `meth.$$owner || #{self.class}`, `meth`, name)};
    }
  end

  def methods(all = true)
    %x{
      var methods = [];

      for (var key in self) {
        if (key[0] == "$" && typeof(self[key]) === "function") {
          if (all == false || all === nil) {
            if (!Opal.hasOwnProperty.call(self, key)) {
              continue;
            }
          }
          if (self[key].$$stub === undefined) {
            methods.push(key.substr(1));
          }
        }
      }

      return methods;
    }
  end

  alias public_methods methods

  def Array(object)
    %x{
      var coerced;

      if (object === nil) {
        return [];
      }

      if (object.$$is_array) {
        return object;
      }

      coerced = #{Opal.coerce_to?(object, Array, :to_ary)};
      if (coerced !== nil) { return coerced; }

      coerced = #{Opal.coerce_to?(object, Array, :to_a)};
      if (coerced !== nil) { return coerced; }

      return [object];
    }
  end

  def at_exit(&block)
    $__at_exit__ ||= []
    $__at_exit__ << block
  end

  # Opal does not support #caller, but we stub it as an empty array to not
  # break dependant libs
  def caller(*args)
    []
  end

  def class
    `self.$$class`
  end

  def copy_instance_variables(other)
    %x{
      var keys = Object.keys(other), i, ii, name;
      for (i = 0, ii = keys.length; i < ii; i++) {
        name = keys[i];
        if (name.charAt(0) !== '$' && other.hasOwnProperty(name)) {
          self[name] = other[name];
        }
      }
    }
  end

{'fraction_non_alphanumeric': 0.16045594037702762, 'fraction_numerical': 0.001972818939061815, 'mean_word_length': 1.9362934362934363, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 5, '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': '4402917', 'n_tokens_mistral': 1604, 'n_tokens_neox': 1542, 'n_words': 399}