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


Just to be sure, I think I should clarify.

I do not mean Ruby ought provide Ara's Map class specifically (though, for the most part it is probably a very good implementation which is why I reference it). But that Ruby provide at least some sort of "Hash with indifferent access" out of the box. In other words, a Hash class that only allows for "text keys" (whether they are symbols or strings under the hood, doesn't matter).

The thing is, more often than not, that is the way we tend to use a Hash. For example, named parameters for methods optimally would use a Hash that makes no distinction String vs Symbol keys.

I figured that a new class is the most likely to be accepted, but I will point out, this could be addressed in another way. If Hash itself supported a key casting procedure, akin to the default value procedure, then we could do something like:

  h = Hash.new
  h.convert_key{ |k| k.to_sym }

  h['a'] = 1
  h  #=> {:a => 1}

If we could do that, then there would be no need of an alternate class. And this would be a much more flexible approach too. But, as I said, I suspect this has less chance of acceptance b/c I suspect it would be problematic implementation wise. For that reason I proposed having the a new class in standard library.



  
----------------------------------------
Feature #3963: Map class in standard library
https://bugs.ruby-lang.org/issues/3963#change-25197

Author: trans (Thomas Sawyer)
Status: Rejected
Priority: Normal
Assignee: akr (Akira Tanaka)
Category: 
Target version: 2.0.0


=begin
 Could we get a class like Ara Howard's Map (http://github.com/ahoward/map) included in Ruby's standard library?
 
 Map is a class that would get a lot of usage. We already see similar classes in other code like Rail's with it's HashWithIndifferentAccess, and my own spin-off from Ruby Facets, the Stash class. It's just one of those things that is genuinely useful. I am not partial to any particular implementation, but I trust Ara's skills and the short name "Map" is pretty nice too.
 
 (Just a side note: Personally I'd prefer the functionality of Map in place of Hash itself, since it has the functionality people want 80% or more of the time, but I realize that is likely to have too many backward compatibility issues for real consideration.)
=end



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