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

The Archive Base Latest Questions

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

I have the following two variables: a = 1; b = ‘a’; I want

  • 0

I have the following two variables:

a = 1;
b = 'a';

I want to be able to do

SOMETYPEOFEVALUATION(b) = 2;

so that the value of variable a is now set to 2.

a # => 2 

Is this possible?

Specifically, I am working with the Facebook API. Each object has a variety of different connections (friends, likes, movies, etc). I have a parser class that stores the state of the last call to the Facebook API for all of these connections. These states are all named corresponding to the the GET you have to call in order to update them.

For example, to update the Music connection, you use https://graph.facebook.com/me/music?access_token=… I store the result in a variable called updated_music. For books, its updated_books. If I created a list of all these connection type names, I ideally want to do something like this.

def update_all
  connection_list.each do |connection_name|
    updated_SomeTypeOfEvalAndConcatenation(connection_name) = CallToAPI("https://graph.facebook.com/me/#{connection_name}?access_token=...")
    end
end

Very new to both Rails and StackOverflow so please let me know if there is a better way to follow any conventions.

Tried the below.

class FacebookParser

attr_accessor   :last_albums_json,         

  def update_parser_vars(service)
     handler = FacebookAPIHandler.new
     connections_type_list = ['albums']
     connections_type_list.each do |connection_name|
       eval "self.last_#{connection_name}_json = handler.access_api_by_content_type(service, #{connection_name})['data']"
     end
    #self.last_albums_json = handler.access_api_by_content_type(service, 'albums')['data']
   end


 end

And I get this error

undefined local variable or method `albums' for #<FacebookParser:0xaa7d12c>

Works fine when I use line that is commented out.

  • 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-27T16:26:11+00:00Added an answer on May 27, 2026 at 4:26 pm

    how about

    eval "#{b}=2"
    

    and with instance variables you can also do instance_variable_set("@name", value)

    EDIT:

    you can also use send method if you have a setter defined(and you have), try this:

    class FacebookParser
      attr_accessor   :last_albums_json,         
    
      def update_parser_vars(service)
        handler = FacebookAPIHandler.new
         connections_type_list = ['albums']
         connections_type_list.each do |connection_name|
           send("last_#{connection_name}_json=", 
             handler.access_api_by_content_type(
               service, connection_name)['data']))
         end
      end
    end
    

    problem with your original code is that

    eval ".... handler.access_api_by_content_type(service, #{connection_name})"
    

    would execute

    ... handler.access_api_by_content_type(service, albums)
    # instead of
    ... handler.access_api_by_content_type(service, 'albums')
    

    so you had to write

    eval ".... handler.access_api_by_content_type(service, '#{connection_name}')" <- the quotes!
    

    this is why people usually avoid using eval – it’s easy to do this kind of mistakes

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

Sidebar

Related Questions

I have following two arrays. I want the difference between these two arrays. That
I have the following two methods that (as you can see) are similar in
Let's say I have any array Trial() As Integer I have two following variables
Suppose I have the following two data structures: std::vector<int> all_items; std::set<int> bad_items; The all_items
I have a variable that will have the following values: blah = # 1,
Let's say I have the following two variables: bob1 = u'bob\xf0\xa4\xad\xa2' bob2 = 'bob\xf0\xa4\xad\xa2'
I have the following program where two variables are to be passed by reference
This is on php I have the following variable on an array Array (
I have the following two pages: Default.aspx Default.aspx.cs How do I access variables in
I have the following problem. I have a data set that has the beginning

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.