Tuesday 15 April 2014

ruby on rails - Create a multidimensional hashwith an adding value -


I currently have a hash that is + = 1

  @ hash = hash New {| Hash, key | Hash [key] = hash.new (0)} hash [string1] [string2] + = 1   

it gives a hash that looks: < Pre> @hash = {string1 = & gt; {String2 = & gt; 1}}

and the increment of that integer value once the same string values ​​are turned on.

Now I need to add a second value to hash ... it looks like ...

  @hash = {string1 = & gt; {String2 = & gt; {String3 = & gt;  

New {| Hash, key | Hash [key] = hash.New (0)} @hash [string1] [string2] [string1] + = 1

string can not be converted into integer " I am feeling a feeling because there is an added element in it, and I have hash.new (0), so it is expecting an integer at that place where I have a string. Is that right?

How do I set this hash so that it can handle an additional dimension and still + = 1 hour So that the price increases?

Thanks.

  irb (Main): 001: 0> h = hash.nu {| h, k | h = ke] = hash.nu {| h, k | h [k] = hash.new (0)}} = & Gt; {} IRB (Main): 002: 0> H [: A] [: b] [: c] + = 1 => 1 IRB (main): 003: 0> H = & Gt; {: A = & gt; {: b = & gt; {: c => 1}}}    

No comments:

Post a Comment