try

[:subject_id, :book_id, :chapter_id, :section_id, :subsection_id,
:minisection_id].each do |k|
 "@#{k.to_s}" = session[k] if session[k].present?
 end

2013/2/17 Dave Castellano <li...@ruby-forum.com>

> Hi,
>
> As I continue learning to program, I am finding things I think can
> probably be done in a better way.  The following code seems like
> something
> programmers must run into all the time and I am wondering if there is a
> better way to write the code in this situation (it seems very repetitive
> to me).  I'm having fun and trying to get better at this....
>
>     if !session[:subject_id].blank?
>         @subject_id = session[:subject_id]
>     end
>
>     if !session[:book_id].blank?
>       @book_id = session[:book_id]
>     end
>
>     if !session[:chapter_id].blank?
>       @chapter_id = session[:chapter_id]
>     end
>
>     if !session[:section_id].blank?
>       @section_id = session[:section_id]
>     end
>
>     if !session[:subsection_id].blank?
>       @subsection_id = session[:subsection_id]
>     end
>
>     if !session[:minisection_id].blank?
>       @minisection_id = session[:minisection_id]
>     end
>
> Is there a better way??
>
> Thanks...
>
> Dave
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rubyonrails-talk+unsubscr...@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>


-- 
att,

Rogerio

A complicação se descomplica na mesma proporção que fazemos os nós se
desatarem ao tecer o conhecimento do saber.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to