Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 615081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:10:53+00:00 2026-05-13T18:10:53+00:00

I have an if statement in my Rails app. I need to do a

  • 0

I have an if statement in my Rails app. I need to do a basic “if true and !false” sort of check. The expression is defined as:

ActiveRecord::Base.connection.tables.include? 'settings' && !Settings.setting_is_set?('defaults_set')

If I put that as my expression to an if, the if will not trigger. If I run that expression in the console, I get false.

Now, if I modify the expression to read:

ActiveRecord::Base.connection.tables.include? 'settings' and not Settings.setting_is_set?('defaults_set')

It returns true as it should, and the executes it’s block.

So the question is: Why is ‘expression && !expression’ not behaving like ‘expression and not expression’. It’s my understanding && and ! should correspond to and and not almost directly.

What am I missing here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:10:53+00:00Added an answer on May 13, 2026 at 6:10 pm

    Its because when you use && Ruby is interpreting the entire end of the string as a single argument being passed to include. Put parenthesis around the 'settings' and the first statement will work fine:

    ActiveRecord::Base.connection.tables.include? 'settings' && !Settings.setting_is_set?('defaults_set')
    # => false
    
    ActiveRecord::Base.connection.tables.include?('settings') && !Settings.setting_is_set?('defaults_set')
    # => true
    

    Somehow, when you use and not it knows that the second part is not part of what is being passed to include and your call succeeds.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have a question about ruby on rails Apparently I have a statement
I'm using dwilkie's foreigner plugin for rails. I have a table creation statement that
I have a statement similar to this that I need to run in Linq.
I have a rails app . I have created a sessionscontroller and want to
In my ruby-on-rails app, I have nested comments that can be nested an arbitrary
In my Rails 3.0.5 app I have columns on my Profile model for privacy.
I have the following statement in Rails 3 using an SQLite3 database: word =
I have a standard Rails app that uses a database, sqlite3 and the webrick
I have a rails app that I am looking into implementing videos. I know
In a Rails 3.2 app I have a model Project, which has many Tasks.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.