StringKeys
A StringKeys object works like a hash, except keys which are not strings are converted to strings.
require 'stringkeys'
sk = StringKeys.new
sk[:name] = 'Fred'
sk.keys[0].class #=> String
The idea is simple. When a key comes in, whether for []
or []=
, if it is
not a string, then its .to_s
method is called and the result is used for the
key. So the following lines produce identical results:
sk[MyClass] = 1
sk[:MyClass] = 1
sk['MyClass'] = 1
Installation
gem install stringkeys
Author
Mike O'Sullivan [email protected]
History
version | date | notes |
---|---|---|
1.0 | Mar 1, 2020 | Initial upload. |