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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:21:27+00:00 2026-06-03T14:21:27+00:00

I want to itterate over a array of key,value pairs from post parameters: Parameters:

  • 0

I want to itterate over a array of key,value pairs from post parameters:

Parameters:
  {"utf8"=>"✓",
  "authenticity_token"=>"c6VYssp33I075nfv1ViPty38+aZSkWM/jh6oll2pYS8=", 
  "permission"=>
    {"employment_id"=>"7", 
     "organisation_level"=>"all_below", 
     "permissions"=>"view_permissions", 
     "users"=>"", 
     "organisation"=>"", 
     "functions"=>"", 
     "statistics"=>""}, 
  "commit"=>"Opslaan"} 

I take the permission map out of these parameters and try to process it. Basically I want to check if the key isn’t employment_id and the value is present.

params.each do |k,v|
  if(!(k.eql?"employment_id") && v.present?)
   p v
  end

end

When running the if statement in this for each I ran into some strange behaviour and I wonder if someone can shine some light on this situation

I ended up with this if statement, it works and evaluates like I expect it to. It only prints the values when the value is not "" or nil and the key isnt employment_id

if(!(k.eql?"employment_id") && v.present?)
  p v
end 

However, The following 2 if statements dont work as I expect. Both print all values. They evaluate to true while I think they shouldn’t.

if(!k.eql?"employment_id" && v.present?)
  p v 
end 

and

if !k.eql?"employment_id" && v.present?
  p v 
end 
  • 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-03T14:21:29+00:00Added an answer on June 3, 2026 at 2:21 pm

    The cause of your confusion is the priority of operations, especially in thew face of you omitting parenthesis. In your case, the statements are evaluated as follows:

    if(!k.eql?"employment_id" && v.present?)
    # equivalent to 
    if (!(k.eql?("employment_id" && v.present?)))
    
    if !k.eql?"employment_id" && v.present?
    # equivalent to 
    if !k.eql?("employment_id" && v.present?)
    

    And here, "employment_id" && v.present? evaluates to true. So essentially, you are asking !k.eql?(true) which, with k being a string always evaluates to true (because of the negation).

    To circumvent the issue, make sure to use parenthesis appropriately. Preferrably you should use them for method calls like so

    k.eql?("employment_id")
    

    instead of like

    (k.eql? "employment_id")
    

    That way, you make it clear what the method arguments are and avoid ambiguities which are then needed to be resolved by precedence. I personally tend to only omit method parenthesis if it is really clear what the arguments are. Especially in more complex statements like yours, it just doesn’t make much sense to omit them and thus reduce clarity.

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

Sidebar

Related Questions

I want to iterate over an array of inputs that belong to certain class
I have the array: example = ['foo', 'bar', 'quux'] I want to iterate over
I want to iterate over all childs of a jQuery's .children() return value, like
I have a String with some value. I want to iterate over all classes
I have an array that I want to iterate over and delete some of
Say I want to add a value to an array, but it doesn't matter
I currently want to iterate over an array of Objects (2 properties: id &
What I need is a key-value container for keeping some well-known parameters of objects.
I have a checkbox list creating an array that I want to iterate over
I want to iterate over a sequence in xquery and grab 2 elements at

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.