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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:20:41+00:00 2026-06-13T13:20:41+00:00

While I am new to Ruby, I have written a number of plugins for

  • 0

While I am new to Ruby, I have written a number of plugins for Ruby through trial and error.

I tried a number of different syntax variations which result in:

  1. Unexpected else or end, expecting }
  2. The variable not getting evaluated properly, i.e. @reUrl will end up = "@reUrl2"

Any help would be appreciated.

Here is an excerpt of my code:

def initialize(config)  
  self.reip1 = config["reip1"]  
  self.reip2 = config["reip2"]  
  @reUrl1 = "#{self.reip1}:8080/redeye/rooms/0/devices/2/commands/send?commandId="  
  @reUrl2 = "#{self.reip2}:8080/redeye/rooms/0/devices/2/commands/send?commandId="  
  @reUrl = @reUrl2  
end  

. 
. 
. 
. 


def change_redeye(redeye)  
  redeye = "#{redeye}".downcase  
  redeye = "#{redeye}".strip  
  redeyeid = "#{@redeyeId["#{redeye}"]}".to_i  
  if redeyeid > 0  
    say "OK. Changing to RedEye #{redeye}."  
    # results in resel = "@reUrl2"  Does what I want.      
    resel = "@reUrl#{redeyeid}"    
    # FIXIT: need to end up with the URL of the device, but can't find the right syntax.     
    @reUrl = "#{#{resel}}"           
  else    
    say "Sorry, I am not programmed to control RedEye #{redeye}."     
  end    
  request_completed     
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-13T13:20:42+00:00Added an answer on June 13, 2026 at 1:20 pm

    tl;dr I finally figured out what you’re trying to do. While the below answer is still completely accurate in regards to your misuse of string interploation, what you’re actually after is instance_variable_get. I was failing to grasp that you were trying to access the value of a variable whose name was stored in a string.


    There is a lot wrong here with your use of strings and interpolation. You only need to use "#{}" when you want to embed a variable inside a string. You’re using it incorrectly in virtually every case. A few specific examples below.

    First, don’t do this:

    redeye = "#{redeye}".downcase
    redeye = "#{redeye}".strip
    

    For one, you’re converting to a string twice. It’s already a string after the first use of #{}. But you shouldn’t be doing that in the first place. If you want to convert a variable to a string, use to_s, and chain your subsequent method calls on the return value of the previous method:

    redeye = redeye.to_s.downcase.strip
    

    This line is really broken, and (as far as I can tell) doesn’t even need string interpolation:

    redeyeid = "#{@redeyeId["#{redeye}"]}".to_i
    

    If @redeyeId is an array of integers, you just need this:

    redeyeId = @redeyeId[redeye]
    

    This line might be syntactically correctly but it’s also pretty broken: This line is correct, if your intent is to use instance_variable_get to access the value of @reUrl1 or @reUrl2:

    "@reUrl#{redeyeid}"
    

    You need to use #{} to interpolate @variable member variables as well as regular variables. The line should probably be

    "#{@reUrl}#{redeyeid}"
    

    This line is also really broken:

    @reUrl = "#{#{resel}}"
    

    What is this even supposed to do? I can’t for the life of me figure out what your intent is here. What you’re actually doing is, inside a string, opening a Ruby context which immediately opens a comment, resulting in the rest of the line being ignored and a syntax error on the following line. I can’t tell what you think this does, but it doesn’t do anything useful.

    Because there is so much wrong here, I’m going to try to write the method as it should be written, and hope you can gain something from it. Before you write any more Ruby, you need to learn what #{} does. It is string interpolation.

    def change_redeye(redeye)
      redeyeid = @redeyeId[redeye.downcase.strip]
    
      if redeyeid > 0
        say "OK. Changing to RedEye #{redeye}."
        @reUrl = instance_variable_get("@reUrl#{redeyeid}")
      else
        say "Sorry, I am not programmed to control RedEye #{redeye}."
      end
      request_completed   
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a new Ruby programmer and have been looking through some tutorials for
I have a BroadcastReceiver that listens for incoming sms messages. While a new sms
While installing the new eclipse indigo IDE I've tried to setup the tomcat server
I have problem on my blog: http://osify.com while processing add new post with above
I am new to Ruby on Rails. I am using Netbeans IDE. While importing
I have this code that I have written in Ruby, but when trying to
I'm brand new to ruby. I've written a little script, and at the top
I am new to Ruby on Rails and I'm trying to go through a
Ruby Version: 1.8 Rails Version: 2.3 I have a class in which I have
I have been working on Ruby on rails project for a while now, when

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.