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

    key = case code
      when 3,4
        :code_a
      when 8,9
        :code_b
      end

    unit_id_hash[key] ||= []
    unit_id_hash[key] << code if key
  end

But the result looks like this:

[{"1113"=>{:code_a=>[8]}, :code_b=>[4]}]

There is an extra "}" in that hash after [8]. THat's strange why that
happens.

The result should look like this:

[{'1113' => {:code_a => [8], :code_b => [4]}}]

Because of the problem I cannot grab the second hash value:

session[:code].detect {|hash| hash["1113"] }["1113"][:code_b]

thanks for response

-- 
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.

Reply via email to