How #{} works

P

Paganoni

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,176
Messages
2,570,947
Members
47,498
Latest member
log5Sshell/alfa5

Latest Threads

Top