Challenge - 5 Problems
Gem Version Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1:30remaining
What is the output of this version comparison?
Given the following Ruby code using Gem::Version, what will be printed?
Ruby
require 'rubygems' v1 = Gem::Version.new('2.3.4') v2 = Gem::Version.new('2.3.10') puts v1 < v2
Attempts:
2 left
💡 Hint
Think about how version numbers are compared as sequences of numbers, not strings.
✗ Incorrect
Gem::Version compares each part of the version number numerically. Since 4 is less than 10, '2.3.4' is less than '2.3.10'.
❓ Predict Output
intermediate1:30remaining
Which gem version satisfies this constraint?
Which of these gem versions satisfies the constraint '~> 3.2.1'?
Attempts:
2 left
💡 Hint
The '~>' operator allows patch-level updates but not minor version bumps.
✗ Incorrect
The '~> 3.2.1' constraint means versions >= 3.2.1 and < 3.3.0. Only 3.2.5 fits this range.
❓ Predict Output
advanced1:30remaining
What error does this gem version constraint raise?
What error will this Ruby code raise when parsing the version constraint?
Ruby
require 'rubygems' Gem::Requirement.new('>= 2.0', '< 3.0', '!= 2.5')
Attempts:
2 left
💡 Hint
Multiple constraints can be combined in Gem::Requirement.
✗ Incorrect
Gem::Requirement accepts multiple constraints as arguments and combines them logically. No error is raised here.
❓ Predict Output
advanced1:30remaining
What is the output of this complex version check?
What will this Ruby code print?
Ruby
require 'rubygems' req = Gem::Requirement.new('~> 1.5', '!= 1.5.3') puts req.satisfied_by?(Gem::Version.new('1.5.3'))
Attempts:
2 left
💡 Hint
The '!=' constraint excludes a specific version even if it matches the '~>' range.
✗ Incorrect
The requirement excludes version 1.5.3 explicitly, so satisfied_by? returns false for that version.
🧠 Conceptual
expert2:00remaining
How many versions satisfy this complex constraint?
Given the constraint '>= 2.0', '< 3.0', '!= 2.5', how many versions in the list satisfy it?
Versions: ['1.9.9', '2.0.0', '2.4.9', '2.5.0', '2.5.1', '3.0.0']
Attempts:
2 left
💡 Hint
Check each version against all constraints carefully.
✗ Incorrect
Versions 2.0.0, 2.4.9, and 2.5.1 satisfy all constraints. 2.5.0 is excluded by '!= 2.5', 1.9.9 is less than 2.0, and 3.0.0 is not less than 3.0.