I’d like to index a hash with a Class (not a symbol !), like the following
irb(main):015:0> class Key ;end
=> nil
irb(main):016:0> h={Key => "ok"}
=> {Key=>"ok"}
Good.
Then, given the name of the Class, as a string, I want the get the element :
irb(main):017:0> str="Key"
=> "Key"
irb(main):018:0> h[str]
=> nil
But (as shown above) this fails (of course).
So my question : how can I transform a String to the actual Class ?
You can use
Kernel#const_get: