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 7899275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:39:30+00:00 2026-06-03T08:39:30+00:00

I accidentally created following check, that works fine, but I’m curious why :) First

  • 0

I accidentally created following check, that works fine, but I’m curious why 🙂

  1. First of all, I know I can assign :a instead of ‘a’ 😉
  2. I know the right formula for this check, I’m just curious why this works
  3. I don’t care about optimizing this (read 2)
if params['a'] < 0 || params['a'] > params['b || params[:b] < 1]

Why this works, if there is no closing after ['b.

Apart from this everything works fine, until I remove last ], or change it to something else.

UPDATE:

Here is output from ruby:

irb> params

 => {"a"=>3, "id2"=>"2", "b"=>2, "id"=>"1", :id=>"2"}

irb> if params['a'] < 0 || params['a'] > params['b' || params[:b] < 1]
irb>   puts 'strange...'
irb> end

strange...

=> nil
  • 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-06-03T08:39:32+00:00Added an answer on June 3, 2026 at 8:39 am

    Well, it certainly looks like you have an open quote which gets closed somewhere else, later down the road, on some other line.

    Fun fact:

    ruby_hash = {}
    ruby_hash['class Atom
    def initialize
    end
    end'] = 0
    

    Works. Because it’s just a string key. So you’re just evaluating a huge long string as a key to to the ‘params’ hash which is most certainly going to evaluate to nil because it’s not an existing key in the hash.


    Edit!
    You edited the question and gave more information. Let’s break this down.

    params = {"a"=>3, "id2"=>"2", "b"=>2, "id"=>"1", :id=>"2"}
    # Simple enough, nothing strange here.
    if params['a'] < 0 || params['a'] > params['b' || params[:b] < 1]
        puts 'strange...'
    end
    The plot thickens, or does it?
    

    If!

    params['a'] < 0
    

    That means, of course: if the value of ” a ” in params is less than 0

    || 
    

    … That means ‘or’

    params['a'] >
    

    Stopping here for a sec – if the value of ‘a’ is greater than….

    params['b' || params[:b] < 1]
    

    Wait, what? Let’s look deeper.

    params[ => We look inside the hash
    'b' || params[:b] < 1 ## HERE IS THE 'MAGIC' => 'b' || params[:b] < 1
    ] # end of the key
    

    So the magic is :
    We want the result of the OR statement between :

    • the string ‘b’
    • the evaluation of ‘params[:b] < 1

    So what is really happening? Well, in truth, since ‘b’ is not false, it will just return the value of params[‘b’], so this is what your if statement really is:

    if params['a'] < 0 || params['a'] > params['b']
    

    If ‘b’ evaluated to false for whatever reason, you would end up with “params[params[b:] < 1]” which in your case would be false and would then means “params[false].

    Does this make sense?

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

Sidebar

Related Questions

How can I remove a shipment that was created accidentally? I know there is
I seem to have accidentally created Visual Studio 2010 tab groups which means that
I know that I am supposed to use std::vector or other alternatives, but there's
I have a database that I had imported and accidentally created some tables as
While attempting to create a replacement tablespace for USER, I accidentally created a datafile
I created a SharePoint sub-site, and accidently deleted all permissions groups except for the
I accidentally closed the Console window in Eclipse, and now I can't see the
I accidentally deleted my bookmarked query in phpMyAdmin. Is there any way it can
I accidentally reverted all my changes with bzr revert before committing. Are all my
.NET newbie alert Using Visual C# 2008 Express Edition I have accidentally created a

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.