Bird
0
0

Which of the following is the correct way to define a method in Ruby following the style guide?

easy📝 Syntax Q3 of 15
Ruby - Ecosystem and Best Practices
Which of the following is the correct way to define a method in Ruby following the style guide?
Adef my_method puts 'Hello' end
Bdef myMethod puts 'Hello' end
Cdef MyMethod puts 'Hello' end
Ddef my-method puts 'Hello' end
Step-by-Step Solution
Solution:
  1. Step 1: Recall Ruby method naming style

    Ruby style guide recommends snake_case for method names.
  2. Step 2: Check each option

    def my_method puts 'Hello' end uses snake_case (my_method), others use camelCase, PascalCase, or invalid syntax.
  3. Final Answer:

    def my_method\n puts 'Hello'\nend -> Option A
  4. Quick Check:

    Method names use snake_case in Ruby [OK]
Quick Trick: Use snake_case for method names in Ruby [OK]
Common Mistakes:
  • Using camelCase for methods
  • Using hyphens in method names
  • Starting method names with uppercase letters

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes