# "Inconsistency" with display/existence of "\\"

**URL:** <https://www.ruby-forum.com/t/inconsistency-with-display-existence-of/180818>\
**Category:** Ruby\
**Created:** [December 29, 2009, 10:01pm UTC](https://www.ruby-forum.com/t/inconsistency-with-display-existence-of/180818 "2009-12-29T22:01:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![trevoke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@trevoke](https://www.ruby-forum.com/u/trevoke)\
**Post date:** [December 29, 2009, 10:01pm UTC](https://www.ruby-forum.com/t/inconsistency-with-display-existence-of/180818/1 "2009-12-29T22:01:36Z")

</div>

Basically, two … Apparently similar objects give me the following  
differing output:  
[3] and [3]  
I pasted most of it up on pastie so it became a bit more readable.

I am taking a text file and reading it like so:  
File.open(filename, ‘r’) { |f| @sgf = f.read }  
It then gets split into an array of single characters.

Here is the rest, though I’m afraid it may not make much sense.  
[http://pastie.org/760500](http://pastie.org/760500)

The gist of it is … Why would a backslash “disappear” ? I mean, the  
files are going through the same code and getting parsed the same way!

---

<div class="post-metadata">

**Author:** ![trevoke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@trevoke](https://www.ruby-forum.com/u/trevoke)\
**Post date:** [December 29, 2009, 10:48pm UTC](https://www.ruby-forum.com/t/inconsistency-with-display-existence-of/180818/2 "2009-12-29T22:48:43Z")

</div>

Aldric G. wrote:

> Basically, two … Apparently similar objects give me the following  
> differing output:  
> [3] and [3]  
> I pasted most of it up on pastie so it became a bit more readable.
> 
> I am taking a text file and reading it like so:  
> File.open(filename, ‘r’) { |f| @sgf = f.read }  
> It then gets split into an array of single characters.
> 
> Here is the rest, though I’m afraid it may not make much sense.  
> [http://pastie.org/760500](http://pastie.org/760500)
> 
> The gist of it is … Why would a backslash “disappear” ? I mean, the  
> files are going through the same code and getting parsed the same way!

You need to boil this down to a minimal test case which demonstrates the  
problem. As you boil it down, you’ll probably find the problem yourself.  
If you don’t, then you’ll have a \<10 line program that you can paste  
here, that we can run, and we can explain any bits of it that you don’t  
understand.

Try using ‘puts x.inspect’ instead of ‘pp x’ - it may be clearer what’s  
going on.

---

<div class="post-metadata">

**Author:** ![trevoke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@trevoke](https://www.ruby-forum.com/u/trevoke)\
**Post date:** [December 29, 2009, 11:20pm UTC](https://www.ruby-forum.com/t/inconsistency-with-display-existence-of/180818/3 "2009-12-29T23:20:42Z")

</div>

Brian C. wrote:

> Try using ‘puts x.inspect’ instead of ‘pp x’ - it may be clearer  
> what’s going on.

Use  
p x

---

<div class="post-metadata">

**Author:** ![trevoke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@trevoke](https://www.ruby-forum.com/u/trevoke)\
**Post date:** [December 31, 2009, 4:29pm UTC](https://www.ruby-forum.com/t/inconsistency-with-display-existence-of/180818/4 "2009-12-31T16:29:47Z")

</div>

Aldric G. wrote:

> I was looking in the wrong place.  
> As it turns out, this happens:
> 
> [“haha”, “baba”, “kate”].each do |x|  
> x.gsub! “a”, “i”  
> end
> 
> actually changes the array - so my save code was modifying the data I  
> had opened.

Glad it’s sorted.

Technically: the above code does not change the array. But it does  
modify the objects which the array contains.

---

<div class="post-metadata">

**Author:** ![trevoke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@trevoke](https://www.ruby-forum.com/u/trevoke)\
**Post date:** [December 31, 2009, 2:22pm UTC](https://www.ruby-forum.com/t/inconsistency-with-display-existence-of/180818/5 "2009-12-31T14:22:09Z")

</div>

Brian C. wrote:

> You need to boil this down to a minimal test case which demonstrates the  
> problem. As you boil it down, you’ll probably find the problem yourself.  
> If you don’t, then you’ll have a \<10 line program that you can paste  
> here, that we can run, and we can explain any bits of it that you don’t  
> understand.
> 
> Try using ‘puts x.inspect’ instead of ‘pp x’ - it may be clearer what’s  
> going on.

I was looking in the wrong place.  
As it turns out, this happens:

[“haha”, “baba”, “kate”].each do |x|  
x.gsub! “a”, “i”  
end

actually changes the array - so my save code was modifying the data I  
had opened.
