SHARE
TWEET

Untitled

a guest Jan 13th, 2013 19 Never
  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
RAW Paste Data
Top