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

On Mon, Oct 3, 2011 at 05:54, sathish kannan [email protected]
wrote:

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


LOOKING FOR WORK, preferably Ruby on Rails, in NoVa/DC; see main web
site.
Main Web S.: davearonson.com
Programming Blog: codosaur.us
Excellence Blog: dare2xl.com