Show Menu
Cheatography

Ruby - Strings - Cheat Sheet (DRAFT) by

ruby string methods examples

This is a draft cheat sheet. It is a work in progress and is not finished yet.

str * integer → new_str

"Ho! " * 3
#=>
"Ho! Ho! Ho! "
"Ho! " * 0
#=>
"­"
Copy — Returns a new String containing integer copies of the receiver. integer must be greater than or equal to 0.

str + other_str → new_str

"­Hello from " + self.to_s
#=>
"­Hello from main"
Concat­ena­tio­n—R­eturns a new String containing other_str concat­enated to str.

str << obj → str / str << integer → str

a = "­hello "
a << "­wor­ld"
#=>
"­hello world"
a << 33
#=>
"­hello world!­"
Appends the given object to str. If the object is an Integer, it is considered a codepoint and converted to a character before being appended.