Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Rails/CompactBlank to handle select(&:present?) #1310

Merged
merged 1 commit into from
Jul 13, 2024

Conversation

fatkodima
Copy link
Contributor

Closes #1308.

@Earlopain
Copy link
Contributor

There's also keep_if to mirror delete_if: https://docs.ruby-lang.org/en/3.3/Array.html#method-i-keep_if

@fatkodima fatkodima force-pushed the compact_blank-select_present branch from 4cea93d to ba3ac50 Compare July 6, 2024 20:11
@@ -33,6 +35,10 @@ module Rails
# collection.delete_if { |_k, v| v.blank? } # Same behavior as `Array#compact_blank!` and `Hash#compact_blank!`
# collection.reject!(&:blank?) # Same behavior as `ActionController::Parameters#compact_blank!`
# collection.reject! { |_k, v| v.blank? } # Same behavior as `ActionController::Parameters#compact_blank!`
# collection.select!(&:present?) # Same behavior as `Array#compact_blank!` and `Hash#compact_blank!`
# collection.select! { |_k, v| v.present? } # Same behavior as `Array#compact_blank!` and `Hash#compact_blank!`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These don't appear to be compatible with Array#compact_blank! and Hash#compact_blank!.

[].select!(&:present?)            #=> nil
[].select! { |_k, v| v.present? } #=> nil
[].compact_blank!                 # => []

{}.select!(&:present?)            #=> nil
{}.select! { |_k, v| v.present? } #=> nil
{}.compact_blank!                 # => {}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed select!.

@fatkodima fatkodima force-pushed the compact_blank-select_present branch from ba3ac50 to df47686 Compare July 8, 2024 19:11
@koic koic merged commit e012af8 into rubocop:master Jul 13, 2024
14 checks passed
@fatkodima fatkodima deleted the compact_blank-select_present branch July 14, 2024 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhancement idea: make Rails/CompactBlank aware of select(&:present?)
3 participants