Bird
0
0

Identify the error in this Ruby code snippet:

medium📝 Debug Q14 of 15
Ruby - Blocks, Procs, and Lambdas
Identify the error in this Ruby code snippet:
class Person
  def name
    "Alice"
  end
end
p = Person.new
m = p.method(name)
m.call
AMissing quotes around method name in <code>method(name)</code>
BCannot call <code>method</code> on an object
CMethod <code>name</code> does not exist
DUsing <code>call</code> on Method object is invalid
Step-by-Step Solution
Solution:
  1. Step 1: Check argument to method

    The argument name is used as a variable, but it should be a symbol or string representing the method name.
  2. Step 2: Correct usage

    It should be p.method(:name) or p.method('name') to get the Method object.
  3. Final Answer:

    Missing quotes around method name in method(name) -> Option A
  4. Quick Check:

    Method name must be symbol or string [OK]
Quick Trick: Always pass method name as symbol or string to method() [OK]
Common Mistakes:
  • Passing bare method name without quotes or colon
  • Thinking method is invalid on objects
  • Confusing call usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes