3 ms·
I'd go with this since it's not performance critical code. Not sure if it's that more readable, but I like it better: BY_NODE_NAMES = HANDLERS.map {|h|
by viraptor 2y ago
I'd go with this since it's not performance critical code. Not sure if it's that more readable, but I like it better:
BY_NODE_NAMES = HANDLERS.map {|h|
h::NODE_NAMES.map {|n| [n, h]}
}.flatten(1).to_h
- ngcazz 2y agoI think we can go harder on the std lib :) HANDLERS.flat_map { _1.node_names.index_with(_1) }.inject(&:merge) (nb: assuming there exists a `.node_names` to expose the constant... just because I like always using method calls)