Suppose I have an enum like this:
enum colors: [:black, :dark_gray, :light_gray, :white]
I want the output as:
[["black",0], ["dark_gray",1], ["light_gray",2], ["white",3]]
or as
[["Black",0], ["Dark gray",1], ["Light gray",2], ["White",3]] #using k.humanize on all keys
How can I get this as output. Also, is this possible from a 1-d array as well. eg.
input=[1,2,3]
output=[[1,1],[2,4],[3,9]]
using something like map etc.
I tried using map function, but the way I tried gives invalid syntax. So I asked it here. The answer should be kind of trivial, however I am missing something.
I tried:
op = colors.keys.map{[|s| s, colors[s]]}
but this is wrong syntax.
SyntaxError: unexpected ']', expecting '}'
map?