Bird
0
0

Which of the following is the correct syntax to call method foo with argument 42 using send on object bar?

easy📝 Syntax Q3 of 15
Ruby - Metaprogramming Fundamentals
Which of the following is the correct syntax to call method foo with argument 42 using send on object bar?
Abar.send(:foo 42)
Bbar.send(:foo, 42)
Cbar.send('foo' 42)
Dbar.send(foo, 42)
Step-by-Step Solution
Solution:
  1. Step 1: Understand send syntax with arguments

    send takes method name as symbol or string, then arguments separated by commas.
  2. Step 2: Check each option

    bar.send(:foo, 42) uses correct symbol and comma. Others miss quotes, colon, or commas causing syntax errors.
  3. Final Answer:

    bar.send(:foo, 42) -> Option B
  4. Quick Check:

    send syntax = send(:method, args...) [OK]
Quick Trick: Separate method name and arguments with commas in send [OK]
Common Mistakes:
  • Omitting commas between arguments
  • Passing method name without colon or quotes
  • Using invalid syntax inside send

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes