Skip to content

A means to add an extension #46

Open

Description

@akimd

I often need to add an extension (be it .tmp or .bak for example).

Writing path.sub_ext("#{path.extname}.tmp") is weird. Likewise for path.sub(/\z/, '.tmp'). And unfortunately + and / have exactly the same semantics, so I can't use that either.

I wish I had add_ext.

Cheers!

Activity

  1. nobu commented on Dec 9, 2025

    @nobu
    Member

    You can do Pathname("#{path}.tmp").

  2. akimd commented on Dec 9, 2025

    @akimd
    Author

    Hi,

    Yes, of course, but it feels unnatural, and more importantly it breaks the chain of calls (including /) by being "prefix" instead of suffix. It makes the result harder to read.

  3. eregon commented on Dec 9, 2025

    @eregon
    Member

    FWIW the path gem has add_ext.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions