Src
Src

Reputation: 5482

Ruby: Integer as key in hash

I need hash like:

name[13][:sub_param1] name[13][:sub_param2]

I've tried:

name = {13: {sub_param1 => 123}}

But it is only possible if 13: is '13': (string)

Upvotes: 0

Views: 2107

Answers (1)

tadman
tadman

Reputation: 211540

I'm not sure what you're doing here, but this works:

name = { 13 => { sub_param1: 123 } }

Note that using the x: notation means that the keys are forced to symbols. If you need to use more exotic key types, which is allowed, you must use the arrow.

Upvotes: 3

Related Questions