Using variable substitution in replace.gsub

How do I include a variable in the 'replace' portion of gsub?

replace.gsub(/#{year}","1/, '#{year}","b')

This outputs:

=> #{year}","b

Let's say year = 2013. I want it to output:

=> 2013","b

Answers


Adding on to Blender's answer, you can use an alternate way of writing strings to avoid having to escape quotes:

replace.gsub(/#{year}","1/, %{#{year}","b})

where %{} is another way to write a string literal that you can do string interpolation in.


Need Your Help

Customize default Android honeycomb ActionMode appearance

android selection android-3.0-honeycomb customization

I'm looking to change (within my application) the default appearance of the ActionMode popup. My UI requirements call for a different appearance for text highlighting than the default green look s...

Losing my padding

jquery html css

I have a website and everything works perfect in google chrome but in IE and firefox I lose my content padding when the browser resizes below 800px.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.