Sha256: f9058bda2ca29cda555dbc5a01830e347a07af5c1f8752995280d20a0db4ccd1

Contents?: true

Size: 548 Bytes

Versions: 2

Compression:

Stored size: 548 Bytes

Contents

# frozen_string_literal: true

require "pathname"

module Refinements
  module Pathnames
    refine Pathname do
      def name
        basename extname
      end

      def copy to
        destination = to.directory? ? to.join(basename) : to
        read.then { |content| destination.write content }
        self
      end

      def rewrite
        read.then { |content| write yield(content) if block_given? }
        self
      end

      def touch at: Time.now
        exist? ? utime(at, at) : write("")
        self
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
refinements-7.2.0 lib/refinements/pathnames.rb
refinements-7.1.0 lib/refinements/pathnames.rb