<commit_before>class File {
  @@open_mode_conversions =
    <['read => "r",
      'write => "w",
      'append => "a",
      'at_end => "a",
      'binary => "b",
      'truncate => "w+"]>

  ruby_aliases: [ 'eof?, 'closed?, 'flush ]
  metaclass alias_method: 'expand_path: for_ruby: 'expand_path

  forwards_unary_ruby_methods

  def File open: filename modes: modes_arr with: block {
    """
    @filename Filename to open/create.
    @modes_arr Array of symbols that describe the desired operations to perform.
    @block @Block@ that gets called with the @File@ object that has been opened.

    Opens a File with a given @filename, a @modes_arr (@Array@) and a @block.

    E.g. to open a File with read access and read all lines and print them to STDOUT:

        File open: \"foo.txt\" modes: ['read] with: |f| {
          { f eof? } while_false: {
            f readln println
          }
        }
    """

    modes_str = modes_str: modes_arr

    try {
      open(filename, modes_str, &block)
    } catch Errno::ENOENT => e {
      IOError new: (e message) . raise!
    }
  }

  def File exists?: filename {
    """
    @filename Path to file to check for existance.
    @return @true if @File@ exists, @false otherwise.

    Indicates if the @File@ with the given @filename exists.
    """

    File exists?(filename)
  }

  def File read: filename {
    """
    @filename @String@ containing the path of the File to be read.
    @return Contents of the File as a @String@.

    Reads all the contens (in ASCII mode) of a given file and returns
    them as an Array of lines being read.
    """

    File read(filename)
  }

  def File read: filename length: length offset: offset (0) {
    """
    @filename @String@ containing the path of the File to be read.
    @length @Fixnum@ being the maximum length to read from the File.
    @offset @Fixnum@ being the offset in bytes to start reading from the File.
    @return Contents of the File as a @String@.

    Reads all the contens (in ASCII mode) of a given file, length and offset
    and returns them as an Array of lines being read.
    """

    File read(filename, length, offset)
  }

  def File open: filename modes: modes_arr (('read, 'binary)) {
    """
    @filename Filename to open/create.
    @modes_arr Array of symbols that describe the desired operations to perform.
    @return A @File@ instance that represents the opened @File@.

    Similar to open:modes:with: but takes no @Block@ argument to be
    called with the @File@ instance.
    Returns the opened @File@ instead and expects the caller to @close it manually.
    """

    modes_str = modes_str: modes_arr
    f = nil
    try {
      f = open(filename, modes_str)
      f modes: modes_arr
    } catch Errno::ENOENT => e {
      IOError new: (e message) . raise!
    }
    f
  }

  def File modes_str: modes_arr {
    """
    @modes_arr Array of symbols that describe the desired operations to perform.
    @return @String@ that represents the @File@ access modifiers, as used by Ruby.

    Returns the appropriate @String@ representation of the @modes_arr.
    """

    str = ""
    modes_arr each: |m| {
      str << (@@open_mode_conversions[m])
    }
    str unique join: ""
  }

  def File delete: filename {
    """
    @filename Path to @File@ to be deleted.

    Deletes a @File@ with a given @filename.
    """

    try {
      delete(filename)
    } catch Errno::ENOENT => e {
      IOError new: (e message) . raise!
    }
  }

  def File delete!: filename {
    """
    @filename Path to @File@ to be deleted.

    Deletes a @File@ with a given @filename. If an @IOError@ occurs,
    it gets ignored.
    """

    try {
      File delete: filename
    } catch IOError {}
  }

  def File directory?: path {
    """
    @path Path to check if it's a @Directory@.
    @return @true, if the @path refers to a @Directory@, @false otherwise.

    Indicates, if a given @path refers to a @Directory@.
    """

    directory?(path)
  }

  def File rename: old_name to: new_name {
    """
    @old_name Path to @File@ to rename.
    @new_name Path to new filename.

    Renames a @File@ on the filesystem.
    """

    File rename(old_name, new_name)
  }

  def File absolute_path: filename {
    """
    @filename Name of @File@ to get absolute path for.
    @return Absolute (expanded) path for @filename.
    """

    File expand_path: filename
  }

  def initialize: path {
    initialize(path)
  }
<commit_msg>add Fancy wrappers for File##join: & File##dirname:<commit_after>class File {
  @@open_mode_conversions =
    <['read => "r",
      'write => "w",
      'append => "a",
      'at_end => "a",
      'binary => "b",
      'truncate => "w+"]>

  ruby_aliases: [ 'eof?, 'closed?, 'flush ]

  metaclass alias_method: 'expand_path: for_ruby: 'expand_path
  metaclass alias_method: 'dirname: for_ruby: 'dirname

  forwards_unary_ruby_methods

  def File open: filename modes: modes_arr with: block {
    """
    @filename Filename to open/create.
    @modes_arr Array of symbols that describe the desired operations to perform.
    @block @Block@ that gets called with the @File@ object that has been opened.

    Opens a File with a given @filename, a @modes_arr (@Array@) and a @block.

    E.g. to open a File with read access and read all lines and print them to STDOUT:

        File open: \"foo.txt\" modes: ['read] with: |f| {
          { f eof? } while_false: {
            f readln println
          }
        }
    """

    modes_str = modes_str: modes_arr

    try {
      open(filename, modes_str, &block)
    } catch Errno::ENOENT => e {
      IOError new: (e message) . raise!
    }
  }

  def File exists?: filename {
    """
    @filename Path to file to check for existance.
    @return @true if @File@ exists, @false otherwise.

    Indicates if the @File@ with the given @filename exists.
    """

    File exists?(filename)
  }

  def File read: filename {
    """
    @filename @String@ containing the path of the File to be read.
    @return Contents of the File as a @String@.

    Reads all the contens (in ASCII mode) of a given file and returns
    them as an Array of lines being read.
    """

    File read(filename)
  }

  def File read: filename length: length offset: offset (0) {
    """
    @filename @String@ containing the path of the File to be read.
    @length @Fixnum@ being the maximum length to read from the File.
    @offset @Fixnum@ being the offset in bytes to start reading from the File.
    @return Contents of the File as a @String@.

    Reads all the contens (in ASCII mode) of a given file, length and offset
    and returns them as an Array of lines being read.
    """

    File read(filename, length, offset)
  }

  def File open: filename modes: modes_arr (('read, 'binary)) {
    """
    @filename Filename to open/create.
    @modes_arr Array of symbols that describe the desired operations to perform.
    @return A @File@ instance that represents the opened @File@.

    Similar to open:modes:with: but takes no @Block@ argument to be
    called with the @File@ instance.
    Returns the opened @File@ instead and expects the caller to @close it manually.
    """

    modes_str = modes_str: modes_arr
    f = nil
    try {
      f = open(filename, modes_str)
      f modes: modes_arr
    } catch Errno::ENOENT => e {
      IOError new: (e message) . raise!
    }
    f
  }

  def File modes_str: modes_arr {
    """
    @modes_arr Array of symbols that describe the desired operations to perform.
    @return @String@ that represents the @File@ access modifiers, as used by Ruby.

    Returns the appropriate @String@ representation of the @modes_arr.
    """

    str = ""
    modes_arr each: |m| {
      str << (@@open_mode_conversions[m])
    }
    str unique join: ""
  }

  def File delete: filename {
    """
    @filename Path to @File@ to be deleted.

    Deletes a @File@ with a given @filename.
    """

    try {
      delete(filename)
    } catch Errno::ENOENT => e {
      IOError new: (e message) . raise!
    }
  }

  def File delete!: filename {
    """
    @filename Path to @File@ to be deleted.

    Deletes a @File@ with a given @filename. If an @IOError@ occurs,
    it gets ignored.
    """

    try {
      File delete: filename
    } catch IOError {}
  }

  def File directory?: path {
    """
    @path Path to check if it's a @Directory@.
    @return @true, if the @path refers to a @Directory@, @false otherwise.

    Indicates, if a given @path refers to a @Directory@.
    """

    directory?(path)
  }

  def File rename: old_name to: new_name {
    """
    @old_name Path to @File@ to rename.
    @new_name Path to new filename.

    Renames a @File@ on the filesystem.
    """

    File rename(old_name, new_name)
  }

  def File absolute_path: filename {
    """
    @filename Name of @File@ to get absolute path for.
    @return Absolute (expanded) path for @filename.
    """

    File expand_path: filename
  }

  def File join: path_components {
    File join(*path_components)
  }

  def initialize: path {
    initialize(path)
  }

{'fraction_non_alphanumeric': 0.10350143140277472, 'fraction_numerical': 0.00022021581149526536, 'mean_word_length': 2.5452771272443404, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 23, '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': '1948640', 'n_tokens_mistral': 2872, 'n_tokens_neox': 2748, 'n_words': 1104}