Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jan 13th, 2013  |  syntax: None  |  size: 0.78 KB  |  views: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. if policy_session[:modalities] #array exists just add new value to it
  2.     policy_session[:modalities] << [params[:modality], policy_session[:mode_list]]
  3. else #the array does't exist yet, so create and add first one.
  4.     policy_session[:modalities] = [params[:modality], policy_session[:mode_list]]
  5.        
  6. >> policy_session[:modalities]
  7. >># [["var_1"], "1",[["var_2"], ["2"]], [["var_3"], ["1"]]]
  8.        
  9. >>policy_session[:modalities]
  10. >># [["var_1", "1"], ["var_2", "2"], ["var_3", "1"]]
  11.        
  12. policy_session[:modalities] ||= [] # set it to an empty array if nil
  13. policy_session[:modalities] << [params[:modality], policy_session[:mode_list]]
  14.        
  15. policy_session[:modalities] ||= [] # set it to an empty array if nil
  16. policy_session[:modalities] << [params[:modality], policy_session[:mode_list]].flatten