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

The Archive Base Latest Questions

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

I have the following code: for attribute in site.device_attributes device.attribute end where I would

  • 0

I have the following code:

for attribute in site.device_attributes   device.attribute end 

where I would like the code to substitute the value of ‘attribute’ for the method name.

I have tried device.'#{attribute}' and various permutations.

Is this completely impossible? Am I missing something?

I have considered overriding method_missing, but I can’t figure out how that would actually help me when my problem is that I need to call an ‘unknown’ method.

  • 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. 2026-05-10T22:13:27+00:00Added an answer on May 10, 2026 at 10:13 pm

    You can use #send method to call object’s method by method’s name:

    object.send(:foo) # same as object.foo 

    You can pass arguments with to invoked method:

    object.send(:foo, 1, 'bar', 1.23) # same as object.foo(1, 'bar', 1.23) 

    So, if you have attribute name in variable ‘attribute’ you can read object’s attribute with

    object.send(attribute.to_sym) 

    and write attribute’s value with

    object.send('#{attribute}='.to_sym, value) 

    In Ruby 1.8.6 #send method can execute any object’s method regardless of its visibility (you can e.g. call private methods). This is subject to change in future versions of Ruby and you shouldn’t rely on it. To execute private methods, use #instance_eval:

    object.instance_eval {   # code as block, can reference variables in current scope }  # or  object.instance_eval <<-CODE   # code as string, can generate any code text CODE 

    Update

    You can use public_send to call methods with regard to visibility rules.

    object.public_send :public_foo # ok object.public_send :private_bar # exception 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 68k
  • Answers 68k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Here is the closest I can find to a official… May 11, 2026 at 12:07 pm
  • added an answer You found out you can also do this: $line=~ tr/\015//d; May 11, 2026 at 12:07 pm
  • added an answer This exception is thrown when the assembly resource handler gets… May 11, 2026 at 12:07 pm

Related Questions

I have the following code: for attribute in site.device_attributes device.attribute end where I would
I have the following code for factory design pattern implementation. class Pen{ public: virtual
I have using the following code for developing tabs. $(document).ready(function() { $('#container-1').tabs(); } ....
I have the following code, for which I get the error: Warning : mysqli_stmt::bind_result()
I have the following code, which is the basis for pagination in a larger
I have a problem with the following code: for(i = 0;(i - 1)< n;i++)
I have the following php code, which has been snipped for brevity. I am
I have code that looks like the following, which works fine for displaying the
I have the following code in a web.config file of the default IIS site.
I have the following code: $bind = new COM(LDAP://CN=GroupName,OU=Groups,OU=Division,DC=company,DC=local); When I execute it from

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.