0
0
Rubyprogramming~20 mins

Gem versions and constraints in Ruby - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Gem Version Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1: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
Afalse
BArgumentError
CSyntaxError
Dtrue
Attempts:
2 left
💡 Hint
Think about how version numbers are compared as sequences of numbers, not strings.
Predict Output
intermediate
1:30remaining
Which gem version satisfies this constraint?
Which of these gem versions satisfies the constraint '~> 3.2.1'?
A3.2.5
B4.0.0
C3.3.0
D3.2.0
Attempts:
2 left
💡 Hint
The '~>' operator allows patch-level updates but not minor version bumps.
Predict Output
advanced
1: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')
ASyntaxError
BNo error, creates requirement successfully
CArgumentError
DTypeError
Attempts:
2 left
💡 Hint
Multiple constraints can be combined in Gem::Requirement.
Predict Output
advanced
1: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'))
AArgumentError
Btrue
Cfalse
DSyntaxError
Attempts:
2 left
💡 Hint
The '!=' constraint excludes a specific version even if it matches the '~>' range.
🧠 Conceptual
expert
2: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']
A3
B4
C2
D5
Attempts:
2 left
💡 Hint
Check each version against all constraints carefully.