I have hash mapping
H = {
"alc" => "AL",
"alco" => "AL",
"alcoh" => "AL",
"alcohol" => "AL",
"alcoholic" => "AL",
}
now I want to use a regex to represent all the keys, like
H={
/^alc/ => “AL”
}
later on I want to use H[“alc”] or H[“alco”] to retrieve the value. But if I use regex, I can not get the value properly. What should I do?
Make a subclass, inherit
Hashclass and override[]behaviour so it checks whether it matches each regex in your hash and returns the corresponding value.