# How to resolve a string in a variable?

**URL:** <https://www.ruby-forum.com/t/how-to-resolve-a-string-in-a-variable/127683>\
**Category:** Rails\
**Created:** [January 31, 2008, 11:52am UTC](https://www.ruby-forum.com/t/how-to-resolve-a-string-in-a-variable/127683 "2008-01-31T11:52:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mohit\_ranka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/898d66/32.png) [@mohit\_ranka](https://www.ruby-forum.com/u/mohit_ranka)\
**Post date:** [January 31, 2008, 11:52am UTC](https://www.ruby-forum.com/t/how-to-resolve-a-string-in-a-variable/127683/1 "2008-01-31T11:52:57Z")

</div>

Hi All,  
I have a string (which contains variable) in a variable

variable\_name = “sample variable”

initial\_string = “#{variable\_name} and the text goes on” (The string  
is being retrieved from Database (as string), so automatic variable  
resolving will not happen)

I need to have

some\_function(initial\_string) -----\> “sample variable and the text  
goes on”

I hope i am clear!

Regards,  
Mohit

---

<div class="post-metadata">

**Author:** ![mohit\_ranka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/898d66/32.png) [@mohit\_ranka](https://www.ruby-forum.com/u/mohit_ranka)\
**Post date:** [January 31, 2008, 3:27pm UTC](https://www.ruby-forum.com/t/how-to-resolve-a-string-in-a-variable/127683/2 "2008-01-31T15:27:04Z")

</div>

mohit\_ranka wrote:

> Hi All,  
> I have a string (which contains variable) in a variable
> 
> variable\_name = “sample variable”
> 
> initial\_string = “#{variable\_name} and the text goes on” (The string  
> is being retrieved from Database (as string), so automatic variable  
> resolving will not happen)
> 
> I need to have
> 
> some\_function(initial\_string) -----\> “sample variable and the text  
> goes on”
> 
> I hope i am clear!
> 
> Regards,  
> Mohit

> > variable\_name = “sample variable”  
> > =\> “sample variable”
> 
> > eval(“variable\_name”)  
> > =\> “sample variable”
> 
> > eval “variable\_name + ’ and the text goes on’”  
> > =\> “sample variable and the text goes on”
