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
Post a Comment