Bang!

Learn about the Bang(!) in Ruby.

We'll cover the following...

Another exciting challenge we should tackle is what we call the “bang,” “exclamation mark,” or just the ! at the end of some methods. Let’s look at the Ruby program below. If we’re using non-English characters on Windows, we may encounter some difficulties with the downcase method:

Press + to interact
# Code example to demonstrate Bang(!)
x = 'I AM COOL'
x = x.downcase # converting string x into lowercase
puts x

Note: The text is “I AM COOL, not “I’M COOL”—we can use that too, but we will need to keep it in double quotes because this phrase contains an apostrophe.

We define the variable with the value “I AM COOL” in all capital letters. On the second line, we redefine the variable and assign a new value to it, resulting in the x.downcase operation. Since x is a string, we have the right to call ...