views:

95

answers:

5
unless scope.nil?
   @page ||= Page.find(id, :scope => Page.find(scope) )
else
   @page ||= Page.find(id)
end
A: 

You could do:

@page ||= unless scope.nil?
  Page.find(id, :scope => Page.find(scope))
else
  Page.find(id)
end
mipadi
A: 

Or:

@page ||= scope.nil? ? Page.find(id) : Page.find(id, :scope => Page.find(scope))
Dimitri
+1  A: 

I would write the block in question like the following. It really comes down to preference, but I find this way to be the most readable.

@page ||=
  if scope
    Page.find id, :scope => Page.find(scope)
  else
    Page.find id
  end
Alex
+2  A: 

This is a bit DRYer:

find_opts = scope.nil? ? {} : {:scope => Page.find(scope)}
@page ||= Page.find(id, find_opts)
glenn jackman
+3  A: 
@page ||=  Page.find id, :scope => (Page.find scope if scope)
ryeguy
this is the neatest certainly, and as mentioned in the end its down to preference of course.
Globalkeith