F4e37ffbbf81653b797ec4cf995a23b1

I'm looking for a compact way to use a default value if the session doesn't contain yet a user-defined value.

def setOrDefault
  setOrDefault = String.new
  if session[:orientation] then setOrDefault = session[:orientation] else setOrDefault = app_config ("orientation") end
  return setOrDefault
end

Refactorings

No refactoring yet !

D41d8cd98f00b204e9800998ecf8427e

Oriol

July 15, 2010, July 15, 2010 12:55, permalink

1 rating. Login to rate!
def setOrDefault
    session[:orientation] || app_config("orientation")
end
F4192eeb4b26e96deab8b5c68926105d

Muke Tever

July 16, 2010, July 16, 2010 22:57, permalink

No rating. Login to rate!

Depending on how you were using this, you might not even need a function.

# If you were doing something like this in your code:
session[:orientation] = setOrDefault

# Then you can just do this instead:
session[:orientation] ||= app_config("orientation")

Your refactoring





Format Copy from initial code

or Cancel