# Problem: Array.to\_s return \[\["..."\]\] in 1.9.0

**URL:** <https://www.ruby-forum.com/t/problem-array-to-s-return-in-1-9-0/127784>\
**Category:** Ruby\
**Created:** [February 1, 2008, 9:25am UTC](https://www.ruby-forum.com/t/problem-array-to-s-return-in-1-9-0/127784 "2008-02-01T09:25:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rollingwoods](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9e5f3/32.png) [@rollingwoods](https://www.ruby-forum.com/u/rollingwoods)\
**Post date:** [February 1, 2008, 9:25am UTC](https://www.ruby-forum.com/t/problem-array-to-s-return-in-1-9-0/127784/1 "2008-02-01T09:25:57Z")

</div>

I use Array.to\_s convert to string. Ruby 1.9.0 return like [[“sample  
string”]], but 1.8.6 return only the value.  
How to resolve this problem? I really don’t want to revise so many lines  
of code. 🙂

Here’s the sample code :

text=“Source String line…”  
d\_lo=text.scan(/Str(.\*?)g/).to\_s  
puts d\_lo

1.8.6 return:in  
1.9.0 return:[[“in”]]

---

<div class="post-metadata">

**Author:** ![rollingwoods](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9e5f3/32.png) [@rollingwoods](https://www.ruby-forum.com/u/rollingwoods)\
**Post date:** [February 1, 2008, 4:11pm UTC](https://www.ruby-forum.com/t/problem-array-to-s-return-in-1-9-0/127784/2 "2008-02-01T16:11:01Z")

</div>

On 01/02/2008, Rk Ch [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I use Array.to\_s convert to string. Ruby 1.9.0 return like [[“sample  
> string”]], but 1.8.6 return only the value.  
> How to resolve this problem? I really don’t want to revise so many lines  
> of code. 🙂

you can define your own version of Array#to\_s which emulates the  
behaviour  
of Ruby 1.8

class Array  
def to\_s  
…your code here…  
end  
end

-Thomas

---

<div class="post-metadata">

**Author:** ![rollingwoods](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9e5f3/32.png) [@rollingwoods](https://www.ruby-forum.com/u/rollingwoods)\
**Post date:** [February 1, 2008, 4:56pm UTC](https://www.ruby-forum.com/t/problem-array-to-s-return-in-1-9-0/127784/3 "2008-02-01T16:56:44Z")

</div>

On Feb 1, 2008, at 3:25 AM, Rk Ch wrote:

> I use Array.to\_s convert to string. Ruby 1.9.0 return like [[“sample  
> string”]], but 1.8.6 return only the value.  
> How to resolve this problem? I really don’t want to revise so many  
> lines  
> of code. 🙂

One option is to switch to Array#join, which also works for nested  
arrays:

> > [1,2,3].join  
> > =\> “123”
> 
> > [1,2,[3,4],5].join  
> > =\> “12345”

---

<div class="post-metadata">

**Author:** ![rollingwoods](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9e5f3/32.png) [@rollingwoods](https://www.ruby-forum.com/u/rollingwoods)\
**Post date:** [February 2, 2008, 11:18am UTC](https://www.ruby-forum.com/t/problem-array-to-s-return-in-1-9-0/127784/4 "2008-02-02T11:18:30Z")

</div>

Rk Ch wrote:

> I use Array.to\_s convert to string. Ruby 1.9.0 return like [[“sample  
> string”]], but 1.8.6 return only the value.  
> How to resolve this problem? I really don’t want to revise so many lines  
> of code. 🙂
> 
> Here’s the sample code :
> 
> text=“Source String line…”  
> d\_lo=text.scan(/Str(.\*?)g/).to\_s  
> puts d\_lo
> 
> 1.8.6 return:in  
> 1.9.0 return:[[“in”]]

Why do you use scan if you don’t really want to scan?  
text=“Source String line…”  
d\_lo=text[/Str(.\*?)g/, 1]  
puts d\_lo

I didn’t test it on 1.9, but it should work the same.

Regards  
Stefan
