Methods Exercise

In case you get stuck anywhere, don't be afraid to ask the coaches! They are here to help and will gladly explain everything to you!

Take notes during the exercises. Even if you never look at them again, they will help you memorise things!

For these exercises, we're only going to use IRB.

Remember: To run IRB, open a command line window (Powershell or Terminal). Then enter the command irb and press Enter.

To exit a running IRB, enter the command exit.

  1. In Ruby, methods names can end with a ?. What’s special about these kinds of methods?

  2. Look at the official Ruby documentation for String. Find 3 methods that end with ?. Read the documentation about them to see what they do and try them out in IRB!

  3. Let’s try chaining some methods. Take the following String: "Good work, well done!". There is a String method which allows you to remove runs of the same character. E.g. "Good" becomes "God". Figure out this method’s name using the String documentation. Call this method on the string, then figure out if the resulting new string has an even number of characters using method chaining. In the end you’ll have joined 3 methods after the string.