Issue #6737 has been updated by trans (Thomas Sawyer).


I attempted to use #fetch as the CRUD method of reading and ran into an issue that may make it infeasible. Because #fetch accepts an argument or block for the default, it never handles the instance-level default or default_proc. In other words, there is no way to have #fetch return the default that was defined upon initialization, e.g.

  h = Hash.new{ |h,k| h[k] = "DEFAULT" }
  h.fetch(:x)  #=> "DEFAULT"

If there is no way for #fetch to do this, then it is not enough to act as the CRUD method for reading. So we would still need to depend on #[], and as a CRUD method, and to the purpose of this ticket, it would be ideal to have a word form for the method to go along with the other CRUD methods.

Btw, if #read is not considered a good choice, perhaps b/c it is to reminiscent of an IO object, then another name like #retrieve would be okay.

----------------------------------------
Feature #6737: Add Hash#read and alias as #[].
https://bugs.ruby-lang.org/issues/6737#change-29913

Author: trans (Thomas Sawyer)
Status: Feedback
Priority: Normal
Assignee: 
Category: core
Target version: 2.0.0


Just, generally speaking it is nice to have a word named method for things when that suites readability better. Most operators (outside of numerical math, of course) have word equivalents. I actually hope you will accept this request based on this merit alone.

But more specifically this is also related to #6442, "CRUDifying" Hash's design. Adding #read is essentially the first step in doing this. Since #read, being the "R" in CRUD, would be one of the core methods, its preferable to have word-named method to go along with other methods, #store (for create and update) and #delete to act as that foundation.

Obviously there is nothing earth shattering here, just asking for an alias at this point. I'd like to incrementally submit requests/patches to "CRUDify" Hash rather then submit one huge patch as it will be much easier to test and ensure backward compatibility that way.



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