0
0
Rubyprogramming~30 mins

Method naming conventions (? and ! suffixes) in Ruby - Mini Project: Build & Apply

Choose your learning style9 modes available
Method naming conventions (? and ! suffixes)
📖 Scenario: You are building a simple Ruby program to check and modify strings. In Ruby, methods that end with ? usually return true or false, and methods that end with ! usually change the object itself.
🎯 Goal: You will create methods with ? and ! suffixes to practice Ruby naming conventions. You will write a method to check if a string contains vowels and another method to remove vowels from the string permanently.
📋 What You'll Learn
Create a method called contains_vowels? that returns true if the string has any vowels.
Create a method called remove_vowels! that removes vowels from the string permanently.
Use the ? suffix for the method that returns a boolean.
Use the ! suffix for the method that modifies the string.
Print the results to show the methods work as expected.
💡 Why This Matters
🌍 Real World
These naming conventions help programmers quickly understand if a method will just check something or if it will change data. This is useful when working on bigger Ruby projects or with other developers.
💼 Career
Knowing Ruby method naming conventions is important for writing clear, maintainable code. Many Ruby jobs expect you to follow these conventions to avoid bugs and improve teamwork.
Progress0 / 4 steps
1
Create a string variable
Create a variable called word and set it to the string "hello world".
Ruby
Need a hint?

Use = to assign the string to the variable word.

2
Create the contains_vowels? method
Define a method called contains_vowels? that takes a string parameter called str and returns true if str contains any vowels (a, e, i, o, u), otherwise false. Use the ? suffix in the method name.
Ruby
Need a hint?

Use a regular expression to check for vowels and return true or false.

3
Create the remove_vowels! method
Define a method called remove_vowels! that takes a string parameter called str and removes all vowels from it permanently. Use the ! suffix in the method name to show it modifies the string.
Ruby
Need a hint?

Use gsub! to change the string by removing vowels.

4
Test and print the results
Call contains_vowels? with word and print the result. Then call remove_vowels! with word and print word again to show it changed.
Ruby
Need a hint?

Use puts to print the results.