Skip to content

Break complex conditional logic #4

Description

@samnang

I see a complex a conditional logic in https://github.com/codereading/rack/blob/rack-1.4/lib/rack/showexceptions.rb#L46

def prefers_plain_text?(env)
  env["HTTP_X_REQUESTED_WITH"] == "XMLHttpRequest" && (!env["HTTP_ACCEPT"] || !env["HTTP_ACCEPT"].include?("text/html"))
end

If I have a long conditional logic like this, I would break each part to make it easy to read:

def prefers_plain_text?(env)
  env["HTTP_X_REQUESTED_WITH"] == "XMLHttpRequest" && 
    !(env["HTTP_ACCEPT"] and env["HTTP_ACCEPT"].include?("text/html"))
end

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions