module ActionView::Helpers::UrlHelper

def link_to_if(condition, name, options = {}, html_options = {}, &block)

# => my_username
# If they are logged in...
# => Login
# If the user isn't logged in...
%>
end
link_to(@current_user.login, { controller: "accounts", action: "show", id: @current_user })
link_to_if(@current_user.nil?, "Login", { controller: "sessions", action: "new" }) do
<%=

# => Login
# If the user isn't logged in...
<%= link_to_if(@current_user.nil?, "Login", { controller: "sessions", action: "new" }) %>
==== Examples

accepts the name or the full argument list for +link_to_if+.
returned. To specialize the default behavior, you can pass a block that
+options+ if +condition+ is true, otherwise only the name is
Creates a link tag of the given +name+ using a URL created by the set of
def link_to_if(condition, name, options = {}, html_options = {}, &block)
  if condition
    link_to(name, options, html_options)
  else
    if block_given?
      block.arity <= 1 ? capture(name, &block) : capture(name, options, html_options, &block)
    else
      ERB::Util.html_escape(name)
    end
  end
end