# How #{} works

**URL:** <https://www.ruby-forum.com/t/how-works/163584>\
**Category:** Ruby\
**Created:** [March 22, 2009, 2:55pm UTC](https://www.ruby-forum.com/t/how-works/163584 "2009-03-22T14:55:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zerohalo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/5fc32e/32.png) [@zerohalo](https://www.ruby-forum.com/u/zerohalo)\
**Post date:** [March 22, 2009, 2:55pm UTC](https://www.ruby-forum.com/t/how-works/163584/1 "2009-03-22T14:55:34Z")

</div>

Can anyone explain this?

> > a = [“b”]  
> > =\> [“b”]
> 
> > a == “b”  
> > =\> false
> 
> > “#{a}” == “b”  
> > =\> true

Since a is an array, how come the last statement evaluates as true?

---

<div class="post-metadata">

**Author:** ![zerohalo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/5fc32e/32.png) [@zerohalo](https://www.ruby-forum.com/u/zerohalo)\
**Post date:** [March 22, 2009, 2:59pm UTC](https://www.ruby-forum.com/t/how-works/163584/2 "2009-03-22T14:59:05Z")

</div>

François Montel wrote:

> =\> true
> 
> Since a is an array, how come the last statement evaluates as true?

“#{ [“b”] }” == [“b”].to\_s #=\> true  
[“b”].to\_s == “b” #=\> true  
[“b”].to\_s #=\> “b”

---

<div class="post-metadata">

**Author:** ![zerohalo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/5fc32e/32.png) [@zerohalo](https://www.ruby-forum.com/u/zerohalo)\
**Post date:** [March 22, 2009, 3:17pm UTC](https://www.ruby-forum.com/t/how-works/163584/3 "2009-03-22T15:17:17Z")

</div>

> > > “#{a}” == “b”
> 
> =\> true
> 
> Since a is an array, how come the last statement evaluates as true?

You could try ruby 1.9, if you prefer false:

> a = [“b”]  
> =\> [“b”]  
> “#{a}” == “b”  
> =\> false  
> “#{a}”  
> =\> “[“b”]”  
> [“b”].to\_s  
> =\> “[“b”]”

---

<div class="post-metadata">

**Author:** ![zerohalo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/5fc32e/32.png) [@zerohalo](https://www.ruby-forum.com/u/zerohalo)\
**Post date:** [March 22, 2009, 8:01pm UTC](https://www.ruby-forum.com/t/how-works/163584/4 "2009-03-22T20:01:14Z")

</div>

le 22/03/2009 14:53, François Montel nous a dit:

> Can anyone explain this?
> 
> > > a = [“b”]  
> > > =\> [“b”]
> > 
> > > a == “b”  
> > > =\> false
> > 
> > > “#{a}” == “b”  
> > > =\> true
> 
> Since a is an array, how come the last statement evaluates as true?

Because, since it’s embedded in a string Ruby does a .to\_s against the  
array. And [“b”].to\_s == “b” is true
