Ruby Method of the Day - String.+

Posted by Kelly McCauley on Aug 30, 2007

Signature

string + other_string   #=> new_string

string.+ returns a new string that is composed of string concatenated with other_string.

Examples

1
2
3
4
5
6
7
"foo" + "bar"           #=> "foobar"
"foo".+("bar")          #=> "foobar"

x = 'foo'
y = 'bar'
z = 'baz'
x + ' ' + z + ' ' + y   #=> "foo baz bar"

Documentation Reference

www.ruby-doc.org : String.+