From: Adam Prescott Date: 2013-02-18T09:02:51+09:00 Subject: Re: Simpler refactor? You could try something like, [:subject_id, :book_id, :chapter_id, :section_id, :subsection_id, :minisection_id].each do |e| instance_variable_set("@#{e}", session[e]) unless session[e].blank? end That only covers refactoring your code as given. Depending on where you then use these instance variables, there might be a neater refactoring by not relying on instance variables. I don't know where you later use them, or what session is an instance of, but there might be a much simpler way by mapping session to non-blank values and using the resulting hashmap where needed.