0
0
Rubyprogramming~10 mins

Method naming conventions (? and ! suffixes) in Ruby - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a method that checks if a number is even using the correct naming convention.

Ruby
def even[1](number)
  number % 2 == 0
end
Drag options to blanks, or click blank then click option'
A_test
B!
C_check
D?
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!' instead of '?' for a method that returns a boolean.
Adding arbitrary suffixes like '_check' or '_test' which are not Ruby conventions.
2fill in blank
medium

Complete the code to define a method that modifies a string in place, following Ruby naming conventions.

Ruby
def capitalize[1](str)
  str.capitalize!
end
Drag options to blanks, or click blank then click option'
A!
B?
C_inplace
D_modify
Attempts:
3 left
💡 Hint
Common Mistakes
Using '?' instead of '!' for methods that modify objects.
Adding suffixes like '_inplace' which are not standard Ruby conventions.
3fill in blank
hard

Fix the error in the method name to follow Ruby conventions for a method that returns a boolean.

Ruby
def valid_email[1](email)
  email.include?('@')
end
Drag options to blanks, or click blank then click option'
A!
B_check
C?
D_valid
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!' for boolean methods.
Using arbitrary suffixes like '_check' or '_valid'.
4fill in blank
hard

Complete the code to define a method that modifies an array in place and returns a boolean indicating success.

Ruby
def add_element[1](array, element)
  array << element
  true
end
Drag options to blanks, or click blank then click option'
A!
B?
D_modify
Attempts:
3 left
💡 Hint
Common Mistakes
Adding '?' after the parameter list which is invalid syntax.
Not using '!' for methods that modify objects.
5fill in blank
hard

Fill both blanks to define a method that checks if a string is empty and modifies it if not, following Ruby conventions.

Ruby
def process_string[1](str)
  if str.empty[2]
    false
  else
    str.upcase!
    true
  end
end
Drag options to blanks, or click blank then click option'
A?
B!
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!' instead of '?' for boolean methods.
Adding suffixes after the parameter list which is invalid.