Project

General

Profile

Actions

Misc #11520

closed

Inconsistent behavior in Array#compact!

Added by postmodern (Hal Brodigan) over 8 years ago. Updated over 8 years ago.

Status:
Rejected
Assignee:
-
[ruby-core:<unknown>]

Description

I noticed that Array#compact! sometimes returns self and other times nil. This behavior was a bit confusing.

[].compact!
# => nil

[1].compact!
# => nil

[nil].compact!
# => []

[1, nil].compact!
# => [1]

I would prefer that Array#compact! either always returns nil, or always returns self.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0