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

With Rails/ActiveRecord 2.3.8 I'd like to do: AnyModel.connection.create_table( 'temp_any_model', temporary: true, id: false, options:
I am creating a rails app and have used this code in one of
I have a rails 2.3.5 app getting upgraded to Rails 3. I did every
I have built a ruby on rails app that lets users track their workouts.
Does rails have a break statement? I'm writing a controller that has some pretty
I have some problem trying to understand when building a rails app with several
I'm in an app that is on Rails 2.3.8, and need to return an
I have a rails app . I have created a sessionscontroller and want to
I have a standard Rails app that uses a database, sqlite3 and the webrick
Let's assume I have two Rails ActiveRecord models, CarType (make/model of car) and Car

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.