Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Style guide: misleading description for "Slicing with Ranges" #953

Open
@ak-lilw

Description

@ak-lilw

In the style guide underSlicing with Ranges it's said that

[0..-1] inary[0..-1] is redundant and simply synonymous withary.

However, one makes a shallow copy while the other doesn't:

ary=[1,2,3]with_slice=ary[0..-1]without_slice=aryary[0]=:changed# [1, 2, 3]putswith_slice.inspect# [:changed, 2, 3]putswithout_slice.inspect

By analogy to the Python idiomary[:], I would guess that the "bad" form is often written specifically to make a copy rather than an alias.

I suggest that the advice be changed to say something likeary.clone,ary.dup or[*ary] is preferred (whatever is considered better style), or that simplyary is preferred if a copy isn't needed. Ifclone is a good alternative then it's worth adding that it isn't exactly synonymous with a full slice, since evenary.clone(freeze: false) clones the singleton class, whereas slicing doesn't.

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


      [8]ページ先頭

      ©2009-2025 Movatter.jp