Turning off interpolation in a regex

I need to be able to find a run of characters (like *count*) in a string and substitute in the value #{object.count} so that I'm left with a string that can itself be interpolated. The method for doing this that jumped out was to use the string's gsub method like this:

  original_string.gsub(/\*count\*/, /count of #{object\.count}/

(Old hands at Ruby are now chuckling, and rightly so) How do I go about getting the literal text in the substitution portion without getting an, "NameError: undefined local variable or method `object' for main:Object"?

Any assistance, pointers or suggestions appreciated.

···

--
Jason Perkins
jperkins@sneer.org

"The computer allows you to make mistakes
faster than any other invention, with the
possible exception of handguns and tequila."

Jason Perkins wrote:

I need to be able to find a run of characters (like *count*) in a string
and substitute in the value #{object.count} so that I'm left with a
string that can itself be interpolated. The method for doing this that
jumped out was to use the string's gsub method like this:

    original_string.gsub(/\*count\*/, /count of #{object\.count}/

(Old hands at Ruby are now chuckling, and rightly so) How do I go about
getting the literal text in the substitution portion without getting an,
"NameError: undefined local variable or method `object' for main:Object"?

s = original_string.gsub(/\*count\*/, 'count of #{object.count}')

# set object somehow

eval "\"#{s}\""

···

--
      vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

Thank you, Joel.

···

On Mar 30, 2006, at 8:53 PM, Joel VanderWerf wrote:

s = original_string.gsub(/\*count\*/, 'count of #{object.count}')

# set object somehow

eval "\"#{s}\""

--
Jason Perkins
jperkins@sneer.org

"The computer allows you to make mistakes
faster than any other invention, with the
possible exception of handguns and tequila."