Bird
0
0

What is the purpose of the def keyword in Ruby?

easy📝 Conceptual Q1 of 15
Ruby - Methods
What is the purpose of the def keyword in Ruby?
ATo define a new method
BTo declare a variable
CTo start a loop
DTo create a class
Step-by-Step Solution
Solution:
  1. Step 1: Understand the role of def

    The def keyword is used in Ruby to start the definition of a method.
  2. Step 2: Differentiate from other keywords

    It is not used for variables, loops, or classes, which have their own keywords.
  3. Final Answer:

    To define a new method -> Option A
  4. Quick Check:

    def keyword = define method [OK]
Quick Trick: Use def to start writing a method in Ruby [OK]
Common Mistakes:
  • Confusing def with variable assignment
  • Using def to start loops
  • Using def to declare classes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes