0
0
Rubyprogramming~30 mins

Bundler for dependency resolution in Ruby - Mini Project: Build & Apply

Choose your learning style9 modes available
Bundler for Dependency Resolution
📖 Scenario: You are building a simple Ruby project that needs external libraries (gems) to work. To manage these libraries easily, you will use Bundler, a tool that helps Ruby projects keep track of and install the right versions of gems.
🎯 Goal: Create a Ruby project that uses Bundler to manage dependencies. You will write a Gemfile listing the gems your project needs, configure Bundler, install the gems, and then write Ruby code that uses one of the installed gems.
📋 What You'll Learn
Create a Gemfile with specific gems and versions
Use Bundler to install the gems
Write Ruby code that requires and uses a gem from the Gemfile
Print output showing the gem is working
💡 Why This Matters
🌍 Real World
Bundler is used in almost every Ruby project to manage external libraries safely and easily. It helps avoid version conflicts and makes sharing projects simple.
💼 Career
Knowing how to use Bundler is essential for Ruby developers, especially when working on web apps, scripts, or any project that depends on third-party gems.
Progress0 / 4 steps
1
Create a Gemfile with dependencies
Create a file named Gemfile and write these exact lines inside it:
source 'https://rubygems.org'
gem 'colorize', '~> 0.8.1'
Ruby
Need a hint?

The Gemfile tells Bundler which gems to install. Use the exact gem name and version.

2
Install gems using Bundler
Run the command bundle install in your terminal to install the gems listed in the Gemfile. Then create a Ruby file named app.rb and write require 'bundler/setup' at the top.
Ruby
Need a hint?

Running bundle install downloads the gems. The require 'bundler/setup' line loads Bundler in your Ruby script.

3
Require and use the gem in Ruby code
In app.rb, add require 'colorize' below require 'bundler/setup'. Then write puts 'Hello, Bundler!'.colorize(:green) to print green text.
Ruby
Need a hint?

The colorize gem lets you print colored text. Use puts with .colorize(:green) to show green text.

4
Run the Ruby script and see the output
Run ruby app.rb in your terminal. The output should be the text Hello, Bundler! shown in green color.
Ruby
Need a hint?

When you run the script, the text should appear in green if your terminal supports colors.