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

  • Home
  • SEARCH
  • 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 6861655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:33:44+00:00 2026-05-27T02:33:44+00:00

I am trying to handle a simple case where i could be getting an

  • 0

I am trying to handle a simple case where i could be getting an object, or a dictionary. So i am either going to get a object like:

obj.fields.nick

or its going to be a dictionary like

obj['nick']

I was wondering if there was a simpler way to do the following:

value = (eval("obj.fields." + field[1]) if obj?.fields ) ? eval("obj['#{field[1]}']")

I was hoping to do something like:

value = (obj?.fields?."#{field[1]}" ) ? eval("obj['#{field[1]}']")  

But if that worked I wouldn’t be writing this post…

I am basically looking for a way to execute a string as part of the if

  • 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-27T02:33:45+00:00Added an answer on May 27, 2026 at 2:33 am
    value = obj.fields?[field] ? obj[field]
    # or
    value = (obj.fields ? obj)[field]
    

    This is the same as

    if obj.fields?
        obj.fields[field]
    else
        obj[field]
    

    There is absolutely no need for eval.

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

Sidebar

Related Questions

Quick overview Trying to insert a Business Object using ObjectDataSource (on a GridView) Get
I'm trying handle bad json data when parsed through json_decode(). I'm using the following
I'm trying to handle Winsock_Connect event (Actually I need it in Excel macro) using
I'm trying to handle this possible exploit and wondering what is the best way
I'm trying to handle the possibility that no arguments and no piped data is
I've been trying to handle the onkeydown event across multiple frames (no, I unfortunately
I am trying to handle the click of custom button in a jqgrid. I
I am trying to handle a drag & drop interaction, which involves mouse down,
I am trying to handle two different WebException 's properly. Basically they are handled
Using Watin, I'm trying to handle a confirm dialog box and tell watin to

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.