0
0
Rubyprogramming~30 mins

Gem versions and constraints in Ruby - Mini Project: Build & Apply

Choose your learning style9 modes available
Gem versions and constraints
📖 Scenario: You are managing a Ruby project that uses gems (libraries). You want to specify exact versions and version constraints for gems in your Gemfile to ensure your project uses the right gem versions.
🎯 Goal: Learn how to write gem version constraints in a Gemfile by specifying exact versions, minimum versions, and version ranges.
📋 What You'll Learn
Create a Gemfile with gem entries
Specify an exact version for one gem
Specify a minimum version constraint for another gem
Specify a version range constraint for a third gem
Print the contents of the Gemfile to verify
💡 Why This Matters
🌍 Real World
Ruby developers use Gemfiles to manage gem versions so their apps run reliably on all machines.
💼 Career
Understanding gem version constraints is essential for Ruby developers, DevOps engineers, and anyone maintaining Ruby applications.
Progress0 / 4 steps
1
Create a Gemfile with three gems
Create a file called Gemfile and add these three gems exactly as shown: gem 'rails', gem 'nokogiri', and gem 'puma' without any version constraints.
Ruby
Need a hint?

Just write each gem line exactly as gem 'gem_name' without versions.

2
Add an exact version constraint for rails
Modify the Gemfile to specify that rails must be exactly version 7.0.4. Keep the other gems unchanged.
Ruby
Need a hint?

Use gem 'rails', '7.0.4' to specify exact version.

3
Add a minimum version constraint for nokogiri
Modify the Gemfile to specify that nokogiri must be version 1.13 or higher. Keep the other gems unchanged.
Ruby
Need a hint?

Use gem 'nokogiri', '>= 1.13' to specify minimum version.

4
Add a version range constraint for puma and print Gemfile
Modify the Gemfile to specify that puma must be between versions 5.0 and 5.5 inclusive. Then write Ruby code to read and print the contents of the Gemfile.
Ruby
Need a hint?

Use gem 'puma', '>= 5.0', '<= 5.5' for version range.
Use puts File.read('Gemfile') to print the file.