Bird
0
0

Given this Ruby code:

medium📝 Predict Output Q5 of 15
Ruby - Ecosystem and Best Practices

Given this Ruby code:

class User
  def initialize(name)
    @name=name
  end
end

What Rubocop offense will it report?

AClass name should be lowercase
BMethod name should be camelCase
CMissing space around assignment operator
DInstance variable should not start with @
Step-by-Step Solution
Solution:
  1. Step 1: Inspect spacing around assignment

    The code @name=name misses spaces around the equals sign, which Rubocop flags.
  2. Step 2: Confirm naming conventions

    Class name is correctly capitalized, method name is snake_case, and instance variables start with @ as expected.
  3. Final Answer:

    Missing space around assignment operator -> Option C
  4. Quick Check:

    Rubocop flags spacing around = operator [OK]
Quick Trick: Put spaces around = for assignments [OK]
Common Mistakes:
  • Ignoring spaces around =
  • Thinking class names should be lowercase
  • Confusing method naming conventions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes