Adding Hash#compact and Hash#compact! methods#13632
Conversation
|
Not sure. The name seems awkward to me. In my the snippet below is clear about the intention. Also, I had a hard time thinking in which cases I'd use this code, and I could not see any usage in regular application. |
|
@rafaelfranca I named as For my usage: instead: yes, I can use |
|
Interesting usage. I think we have some code like this even inside Rails. I'll delegate to @dhh who is better naming things than I 😄 |
|
As a side note, given your use case, Rails has you covered: Would output: Rails already ignores attributes containing |
|
Nice to know that Rails already ignore nil values for Helpers. |
|
I'm sympathetic to this idea. I even think the name parity with Array#compact makes sense. I do remember writing similar code in the past. So 👍 on name and method from me. |
|
Great! Lets get this in. @tinogomes we need to upgrade the active_support guides and we need a CHANGELOG entry. |
There was a problem hiding this comment.
You should be able to use dup.compact!, right?
|
@carlosantoniodasilva @rafaelfranca active_support guides and CHANGELOG updated and all your suggestions done! |
There was a problem hiding this comment.
put this in alphabetical order with other requires
|
@egilburg all done! |
|
@tinogomes you'll need to squash your commits. |
There was a problem hiding this comment.
why select here and reject below? We can have the same implementation at both the places?
There was a problem hiding this comment.
Benchmark for better solution:
* Adding Hash#compact and Hash#compact! methods * Using Ruby 1.9 syntax on documentation * Updating guides for `Hash#compact` and `Hash#compact!` methods * Updating CHANGELOG for ActiveSupport * Removing unecessary protected method and lambda for `Hash#compact` implementations * Performing `Hash#compact` implementation - https://gist.github.com/tinogomes/8332883 * fixing order position * Fixing typo
|
squashed! |
Adding Hash#compact and Hash#compact! methods
|
❤️ 💚 💙 💛 💜 |
|
👍 |
Example:
Benchmark for better solution:
https://gist.github.com/tinogomes/8332883