thanks for response. I see what you are trying to say, but this line
right here:
s_code << {unit_id => unit_id_hash}
it just creates a hash like this:
{unit_id => {}}
and then latter we insert items into it, always the same way, whether
it's the first time we insert item or not:
unit_id_hash[key] << code if key
So if you see a problem here, maybe I am not understanding.
thanks for response
On Oct 18, 6:26 am, Frederick Cheung <[email protected]>
wrote:
> On Oct 17, 10:27 pm, John Merlino <[email protected]> wrote:
>
> > Hey all,
>
> > THis line of code gets called multiple times and creates a hash:
>
> > def session_code(unit_id, code)
>
> > s_code = session[:code]
> > unit_id_hash = s_code.detect {|h| h[unit_id]}
>
> > if unit_id_hash.nil?
> > unit_id_hash = {}
> > s_code << {unit_id => unit_id_hash}
> > end
>
> The two branches of this code result in unit_id_hash looking somewhat
> different .
>
> In the case where you find something in s_code, what you're setting
> unit_id_hash to is something of the form {unit_id => {...}} whereas I
> expect you're expect it to be the value from that hash for the key
> unit_id
>
> Fred
--
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.