Use case for using array as ruby hash key -


ruby allows using array hash key shown below:

hash1 = {1 => "one", [2] => 'two', [3,4] => ['three', 'four']} 

i not clear on common use case be. if people can share real-world scenarios useful, appreciate it.

a great example why you'd want store arrays hash keys memoizing.

this example of how array hash key useful:

def initialize(*args)   @memoizer ||= {}   return @memoizer[args] if @memoizer[args]   # args in initializer,    # create new instance future.   @memoizer[args] = some_calculation(args) end 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -