Ruby Gsub! question?

And params:hello are references to the same string. In ruby (as in java and python among others) assignment does not copy the value, it just stores another reference to the same value in the assigned-to variable. So unless you explicitly copy the string before modifying it (using dup ) any changes to the string will affect all other references to the string.

And params:hello are references to the same string. In ruby (as in java and python among others) assignment does not copy the value, it just stores another reference to the same value in the assigned-to variable. So unless you explicitly copy the string before modifying it (using dup) any changes to the string will affect all other references to the string.

There are two versions of String#gsub available a= "abc" # => "abc" b= a. Gsub("b", "2") # "a2c" a # => "abc" c= a. Gsub!("c", "3") # => "ab3" a # => "ab3" String#gsub!

Modifies the original string and returns a reference to it. String#gsub does not modify the original and makes the replacement on a copy. It is a common ruby idiom to name methods which modify the object with a!.

If you don't want it to be modified, you need to clone it, like: hello = params:hello. Clone The way you're doing it now, you have a reference to it, not a copy.

You are using the block form when calling gsub! , but the string in your hash is attempting to use the form in which a string is passed in. Furthermore, the variable interpolation in your string is occurring before the match; variable interpolation happens as soon as the string is evaluated, which is at the time your hash is being constructed, while for this to work you would need variable interpolation to happen after the subexpression replacement happens (which is never the case; variable interpolation will happen first, and the resulting string would be passed in to gsub!

To substitute the subexpression match for $1, but $1 would have already been evaluated and no longer in the string, as the interpolation has already occurred). Now, how to fix this? Well, you probably want to store your blocks directly in the hash (so that the strings won't be interpreted while constructing the hash, but instead when gsub!

Invokes the block), with an argument corresponding to the match, and $1, $2, etc. bound to the appropriate subexpression matches.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions