ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:92538] [Ruby trunk Feature#15822] Add Hash#except
       [not found] <redmine.issue-15822.20190504135004@ruby-lang.org>
@ 2019-05-04 13:50 ` timo
  2019-10-17  6:42 ` [ruby-core:95386] [Ruby master " matz
  2019-10-17 14:32 ` [ruby-core:95394] " zverok.offline
  2 siblings, 0 replies; 3+ messages in thread
From: timo @ 2019-05-04 13:50 UTC (permalink / raw
  To: ruby-core

Issue #15822 has been reported by timoschilling (Timo Schilling).

----------------------------------------
Feature #15822: Add Hash#except
https://bugs.ruby-lang.org/issues/15822

* Author: timoschilling (Timo Schilling)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
According to `Hash#slice`, I would like to add `Hash#except`. Same for `ENV.except`.

---Files--------------------------------
hash-except.patch (4.11 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-core:95386] [Ruby master Feature#15822] Add Hash#except
       [not found] <redmine.issue-15822.20190504135004@ruby-lang.org>
  2019-05-04 13:50 ` [ruby-core:92538] [Ruby trunk Feature#15822] Add Hash#except timo
@ 2019-10-17  6:42 ` matz
  2019-10-17 14:32 ` [ruby-core:95394] " zverok.offline
  2 siblings, 0 replies; 3+ messages in thread
From: matz @ 2019-10-17  6:42 UTC (permalink / raw
  To: ruby-core

Issue #15822 has been updated by matz (Yukihiro Matsumoto).


`Hash#slice` was introduced via discussion in #13563. We didn't see the need for `Hash#except` yet. Any (real world use-case)?
I don't think the name `except` is the best name for the behavior.

Matz.

----------------------------------------
Feature #15822: Add Hash#except
https://bugs.ruby-lang.org/issues/15822#change-82099

* Author: timoschilling (Timo Schilling)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
According to `Hash#slice`, I would like to add `Hash#except`. Same for `ENV.except`.

---Files--------------------------------
hash-except.patch (4.05 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-core:95394] [Ruby master Feature#15822] Add Hash#except
       [not found] <redmine.issue-15822.20190504135004@ruby-lang.org>
  2019-05-04 13:50 ` [ruby-core:92538] [Ruby trunk Feature#15822] Add Hash#except timo
  2019-10-17  6:42 ` [ruby-core:95386] [Ruby master " matz
@ 2019-10-17 14:32 ` zverok.offline
  2 siblings, 0 replies; 3+ messages in thread
From: zverok.offline @ 2019-10-17 14:32 UTC (permalink / raw
  To: ruby-core

Issue #15822 has been updated by zverok (Victor Shepelev).


@matz About use-cases, there are multiple, like:

* Logging/debug printing some hash with sensitive or too large data excluded: 

  ```ruby
  puts "REQUEST: #{request_data.except(:body, :apikey)}
  ```

* Data tidying: 

  ```ruby
  CSV.read('data.csv', headers: true).map(&:to_h).map { |row| OpenStruct.new(row.except("Manager comment")) }
  ```

* Data conversion:

  ```ruby
  paragraphs.map { |para| ParaStats.new(para.to_h.except(:text)) }
  ```

...and so on (without even mentioning working with models in Rails, where it is used extensively to, for example, copy model without its id and timestamps). 
Redmine's sources, for example, make some use of it:
```bash
$ grep -F ".except(" {app,lib} -r | wc -l
27
```
I recently [stumbled upon it, too](https://github.com/zverok/time_calc/blob/master/lib/time_calc/types.rb#L58).

About the name: I understand "ActiveSupport uses this name" is kinda lazy one, but it does :) And, TBH, for me (even before I started working with Rails, I used Ruby for first my 12 years without ActiveSupport) it always felt natural: `request.except(:path, :body)` requires no further explanations. Facets [uses the name](https://www.rubydoc.info/github/rubyworks/facets/Hash#except-instance_method), too.

The alternative method name I can think of is, maybe, descriptive `without_keys(*keys)` (or `except_keys`, or just `without(*keys)`), but I am not sure it is any better.

----------------------------------------
Feature #15822: Add Hash#except
https://bugs.ruby-lang.org/issues/15822#change-82107

* Author: timoschilling (Timo Schilling)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
According to `Hash#slice`, I would like to add `Hash#except`. Same for `ENV.except`.

---Files--------------------------------
hash-except.patch (4.05 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-10-17 14:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <redmine.issue-15822.20190504135004@ruby-lang.org>
2019-05-04 13:50 ` [ruby-core:92538] [Ruby trunk Feature#15822] Add Hash#except timo
2019-10-17  6:42 ` [ruby-core:95386] [Ruby master " matz
2019-10-17 14:32 ` [ruby-core:95394] " zverok.offline

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).