Using constants as indices for JavaScript associative arrays

In ECMAScript 6 you can use computed values for object keys: var CONSTANT_A = 0, CONSTANT_B = 1 var state_machine = { [CONSTANT_A]: function () { return ‘a’ }, [CONSTANT_B]: function () { return ‘b’ } }; console.log(state_machine) This does not work in Internet Explorer 11 nor in Safari browsers: https://kangax.github.io/compat-table/es6/#test-object_literal_extensions_computed_properties

Associative Arrays in Ruby

Unlike PHP which conflates arrays and hashes, in Ruby (and practically every other language) they’re a separate thing. http://ruby-doc.org/core/classes/Hash.html In your case it’d be: a = {‘Peter’ => 32, ‘Quagmire’ => ‘asdas’} There are several freely available introductory books on ruby and online simulators etc. http://www.ruby-doc.org/