Note that there are some explanatory texts on larger screens.

plurals
  1. PORuby 1.9 Array.to_s behaves differently?
    text
    copied!<p>i wrote a quick little application that takes a base file of code with some keywords, a file of replacements for the keywords, and outputs a new file with the keywords replaced.</p> <p>When i was using Ruby 1.8, my outputs would look fine. Now when using Ruby 1.9, my replaced code has the newline characters in it instead of line feeds. </p> <p>For example, i see something like:</p> <pre><code>["\r\nDim RunningNormal_1 As Boolean", "\r\nDim RunningNormal_2 As Boolean", "\r\nDim RunningNormal_3 As Boolean"] </code></pre> <p>instead of:</p> <pre><code>Dim RunningNormal_1 As Boolean Dim RunningNormal_2 As Boolean Dim RunningNormal_3 As Boolean </code></pre> <p>i use a hash of replacements {"KEYWORD"=>["1","2","3"]} and an array of the replaced lines.</p> <p>i use this block to finish the replacement:</p> <pre><code>resultingLibs.each do |x| libraryString.sub!(/(&lt;REPEAT&gt;(.*?)&lt;\/REPEAT&gt;)/im) do |match| x.each do |individual| individual.to_s end end end #for each resulting group of the repeatable pattern, # #Write out the resulting libs to a combined string </code></pre> <p>My hunch is that i'm printing out the array instead of the strings within the array. Any suggestions on a fix. When i debug and print my replaced string using puts, the output looks correct. When i use the to_s method (which is how my app writes the output to the output file), my output looks wrong.</p> <p>A fix would be nice, but what i really want to know is what changed between Ruby 1.8 and 1.9 that causes this behavior. Has the to_s method changed somehow in Ruby 1.9?</p> <p>*i'm inexperienced in Ruby</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload