When nothing isn't

So factor it out.

def my_something
  @my_something ||= (session[:somethingorotherarray] || [])
end

def my_something=(s)
  @my_something = session[:somethingorotherarray] = s
end

Now if it's not defined in the session you'll get a blank array back.

It's a pretty basic principle...if you see duplication, factor it out.

Pat

p.s. it's definitely not a good idea to stick a full array of objects
in the session...at most you'd want a string/array containing the IDs
of objects

I'd be more tempted to write:

myhash[:foo].size rescue 0

Wes Gamble-2 wrote: