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 !
Oriol
July 15, 2010, July 15, 2010 12:55, permalink
def setOrDefault
session[:orientation] || app_config("orientation")
end
Muke Tever
July 16, 2010, July 16, 2010 22:57, permalink
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")
I'm looking for a compact way to use a default value if the session doesn't contain yet a user-defined value.