0
0
Rubyprogramming~5 mins

Method naming conventions (? and ! suffixes) in Ruby - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does a method name ending with a ? usually indicate in Ruby?
It indicates that the method returns a boolean value (true or false), often used for predicate methods that ask a question about an object.
Click to reveal answer
beginner
What is the purpose of a method name ending with a ! in Ruby?
It signals that the method is "dangerous" or performs its action in a more surprising or destructive way, often modifying the object in place.
Click to reveal answer
intermediate
Can a method have both ? and ! suffixes in Ruby?
No, Ruby does not allow method names to end with both ? and ! at the same time.
Click to reveal answer
beginner
Why should you use ? suffix only for methods that return boolean values?
Because it helps other programmers understand that the method answers a yes/no question, improving code readability and intention clarity.
Click to reveal answer
intermediate
Give an example of a Ruby method with a ! suffix and explain its behavior.
Example: upcase! modifies the string in place to uppercase letters, unlike upcase which returns a new string without changing the original.
Click to reveal answer
What does a Ruby method ending with ? usually return?
AA boolean value (true or false)
BA modified object
CAn error message
DA string
What does the ! suffix in a Ruby method name usually warn about?
AThe method is slow
BThe method modifies the object or is dangerous
CThe method returns a boolean
DThe method is deprecated
Which of these is a valid Ruby method name?
Adangerous_method!
Bvalid_method?
Ccheck_method?!
Dmethod!?
Why is it important to follow the ? and ! naming conventions in Ruby?
ATo make code run faster
BTo make methods private
CTo improve code readability and communicate method behavior
DTo avoid syntax errors
What does the method empty? typically check in Ruby?
AIf a number is zero
BIf an object is nil
CIf a method is dangerous
DIf a collection or string has no elements or characters
Explain the difference between Ruby methods ending with ? and those ending with !.
Think about how these suffixes help communicate what the method does.
You got /4 concepts.
    Why is it helpful to use ? and ! suffixes in method names when writing Ruby code?
    Consider how naming conventions affect teamwork and maintenance.
    You got /4 concepts.