Bird
0
0

Which of the following is the correct syntax to get a Method object for the method greet on object person?

easy📝 Syntax Q12 of 15
Ruby - Blocks, Procs, and Lambdas
Which of the following is the correct syntax to get a Method object for the method greet on object person?
Aperson.send(:greet)
Bperson.method[b greet]
Cperson.method(greet)
Dperson.method(:greet)
Step-by-Step Solution
Solution:
  1. Step 1: Check argument type for method

    The method method expects a symbol representing the method name.
  2. Step 2: Validate options

    person.method(:greet) uses a symbol :greet, which is correct. person.send(:greet) calls the method directly, returning its result instead of a Method object. person.method(greet) passes an undefined variable greet, causing error. person.method[b greet] uses brackets, which is invalid syntax.
  3. Final Answer:

    person.method(:greet) -> Option D
  4. Quick Check:

    Use symbol argument with method [OK]
Quick Trick: Use a symbol like :greet inside method() [OK]
Common Mistakes:
  • Confusing method() with send()
  • Using brackets instead of parentheses
  • Passing undefined variable instead of symbol

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes