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

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Dave Aronson at Oct 3, 2011 at 11:43 am

    On Mon, Oct 3, 2011 at 05:54, sathish kannan 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 http://www.ruby-doc.org/core/classes/Hash.html 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 Site: davearonson.com
    Programming Blog: codosaur.us
    Excellence Blog: dare2xl.com

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedOct 3, '11 at 9:54a
activeOct 3, '11 at 11:43a
posts2
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Sathish kannan: 1 post Dave Aronson: 1 post

People

Translate

site design / logo © 2021 Grokbase