append the hash error

Hi,

i want to capture a obj.errors value into a new hash for example

a = Hash.new obj.errors = { :a => “can’t be blank” , :b =>“should be alphanumeric” ,:c => “Not in the list”} a << {0 , obj.errors} end

it says error like that

undefined method `<<' for {}:Hash

pls what i miss in this syntax

thanks in advance

a << {0 , obj.errors}

...

undefined method `<<' for {}:Hash

pls what i miss in this syntax

What it's trying to tell you is that the line I quoted above is syntactically incorrect -- that Class Hash does not have a << method. See class Hash - RDoc Documentation for more info on hashes.

But to take this a step further, are you sure you want to store it in a hash, not an array? Arrays do have a << method, and it doesn't look to me like you're storing obj.errors under a really meaningful key.

If you really do want to store obj.errors as the value for key 0, that would be done as:

  a[0] = obj.errors

or if you want to store the zero as a string not a number,

  a['0'] = obj.errors

-Dave