Bird
0
0

Why does the pessimistic operator ~> behave differently when used with two-part versions (e.g., ~> 2.3) versus three-part versions (e.g., ~> 2.3.0)?

hard📝 Conceptual Q10 of 15
Ruby - Gems and Bundler
Why does the pessimistic operator ~> behave differently when used with two-part versions (e.g., ~> 2.3) versus three-part versions (e.g., ~> 2.3.0)?
ABecause with two parts it locks major version, with three parts it locks minor version
BBecause with two parts it allows minor version updates, with three parts only patch updates
CBecause with two parts it allows major updates, with three parts it allows minor updates
DBecause with two parts it allows patch updates, with three parts it allows major updates
Step-by-Step Solution
Solution:
  1. Step 1: Understand the behavior of ~> with two-part versions

    When used with two parts like ~> 2.3, it means >= 2.3 and < 3.0, allowing minor version updates.
  2. Step 2: Understand the behavior of ~> with three-part versions

    When used with three parts like ~> 2.3.0, it means >= 2.3.0 and < 2.4.0, allowing only patch updates within the minor version.
  3. Final Answer:

    Because with two parts it allows minor version updates, with three parts only patch updates -> Option B
  4. Quick Check:

    Two-part ~> allows minor updates, three-part locks minor = Because with two parts it allows minor version updates, with three parts only patch updates [OK]
Quick Trick: Two-part ~> allows minor updates; three-part ~> locks minor version [OK]
Common Mistakes:
  • Confusing minor and patch updates
  • Assuming ~> always locks major version
  • Ignoring the number of version parts

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes