Bird
Raised Fist0
Rubyprogramming~20 mins

Bundler for dependency resolution in Ruby - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Bundler Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output of this Bundler command?
You run bundle list in a Ruby project with a Gemfile containing gem 'rack', '~> 2.2'. What will Bundler display?
Ruby
bundle list
A
Gems included by the bundle:
  * rack (2.2.3)
BCould not find gem 'rack (~> 2.2)' in any of the sources
CFetching gem metadata from https://rubygems.org/...
DBundler version 2.3.0
Attempts:
2 left
💡 Hint
Think about what bundle list shows after gems are installed.
🧠 Conceptual
intermediate
1:30remaining
What does the Gemfile.lock file do?
In a Ruby project using Bundler, what is the main purpose of the Gemfile.lock file?
AIt contains the source code of all gems used in the project.
BIt records the exact versions of gems installed to ensure consistent installs.
CIt specifies the Ruby version required by the project.
DIt lists all available gems on RubyGems.org.
Attempts:
2 left
💡 Hint
Think about how Bundler ensures everyone uses the same gem versions.
🔧 Debug
advanced
2:30remaining
Why does this Bundler install fail?
You run bundle install but get this error:
Bundler could not find compatible versions for gem "rails":
In Gemfile:
rails (~> 6.1.0)

Another dependency requires rails (~> 7.0)

What is the cause?
AThe network connection to RubyGems.org is down.
BThe Gemfile.lock is missing, so Bundler cannot install gems.
CThe Gemfile requests rails 6.1.x but another dependency requires rails 7.0 or higher.
DThe Ruby version is incompatible with rails 6.1.
Attempts:
2 left
💡 Hint
Look at the version requirements in the error message.
📝 Syntax
advanced
2:00remaining
Which Gemfile syntax is correct for specifying a source and a gem with a version constraint?
Choose the correct Gemfile syntax to specify RubyGems.org as the source and include the gem 'nokogiri' version '~> 1.12'.
A
source = 'https://rubygems.org'
gem 'nokogiri', version: '~> 1.12'
B
source: 'https://rubygems.org'
gem 'nokogiri' version '~> 1.12'
C
source('https://rubygems.org')
gem('nokogiri', '~> 1.12')
D
source 'https://rubygems.org'
gem 'nokogiri', '~> 1.12'
Attempts:
2 left
💡 Hint
Gemfile uses Ruby DSL syntax, not hash or method calls.
🚀 Application
expert
3:00remaining
How to update a single gem without changing others?
You want to update only the 'puma' gem to the latest compatible version without updating other gems in your bundle. Which Bundler command should you use?
Abundle update puma
Bbundle upgrade puma
Cbundle install --update puma
Dbundle install --only puma
Attempts:
2 left
💡 Hint
Check Bundler's command to update specific gems.

Practice

(1/5)
1. What is the main purpose of Bundler in a Ruby project?
easy
A. To run Ruby code faster by caching results
B. To compile Ruby code into machine language
C. To create user interfaces for Ruby applications
D. To manage and install gem dependencies with specific versions

Solution

  1. Step 1: Understand Bundler's role

    Bundler is designed to handle gem dependencies and ensure the correct versions are used in a project.
  2. Step 2: Compare options

    Options B, C, and D describe unrelated tasks like compiling, UI creation, or caching, which Bundler does not do.
  3. Final Answer:

    To manage and install gem dependencies with specific versions -> Option D
  4. Quick Check:

    Bundler = dependency manager [OK]
Hint: Bundler manages gems and versions for your Ruby project [OK]
Common Mistakes:
  • Confusing Bundler with Ruby interpreter
  • Thinking Bundler compiles code
  • Assuming Bundler creates user interfaces
2. Which of the following is the correct command to install gems listed in a Gemfile using Bundler?
easy
A. bundle install
B. gem install
C. bundle update
D. ruby install

Solution

  1. Step 1: Identify the command to install gems from Gemfile

    The command bundle install reads the Gemfile and installs the specified gems.
  2. Step 2: Differentiate from other commands

    gem install installs a single gem, bundle update updates gems, and ruby install is invalid.
  3. Final Answer:

    bundle install -> Option A
  4. Quick Check:

    Install gems with bundle install [OK]
Hint: Use 'bundle install' to install all gems from Gemfile [OK]
Common Mistakes:
  • Using 'gem install' instead of 'bundle install'
  • Confusing 'bundle update' with install
  • Typing invalid commands like 'ruby install'
3. Given this Gemfile content:
source 'https://rubygems.org'
gem 'rack', '~> 2.2.0'
gem 'puma', '5.0.4'

What will Bundler do when you run bundle install?
medium
A. Install rack version 2.2.x and puma version 5.0.4
B. Install latest versions of rack and puma ignoring specified versions
C. Install rack version 2.2.0 exactly and puma version 5.0.4
D. Fail because version constraints are invalid

Solution

  1. Step 1: Understand version constraints in Gemfile

    The '~> 2.2.0' means any version >= 2.2.0 and < 2.3.0 for rack. The puma gem is fixed at 5.0.4.
  2. Step 2: What does Bundler do on install?

    Bundler installs rack in the 2.2.x range and puma exactly at 5.0.4, respecting constraints.
  3. Final Answer:

    Install rack version 2.2.x and puma version 5.0.4 -> Option A
  4. Quick Check:

    ~> means compatible version range [OK]
Hint: ~> means 'compatible with' version, not exact [OK]
Common Mistakes:
  • Thinking '~>' means exact version
  • Assuming latest versions install ignoring constraints
  • Believing version constraints cause install failure
4. You run bundle install but get an error: Could not find gem 'rails (~> 6.1.0)' in any of the sources. What is the most likely cause?
medium
A. The Gemfile is missing the source URL
B. The specified version of rails is not available in the gem sources
C. You forgot to run bundle update before install
D. The Ruby version is incompatible with rails

Solution

  1. Step 1: Analyze the error message

    The error says Bundler cannot find the gem 'rails' with version '~> 6.1.0' in any source.
  2. Step 2: Identify common causes

    This usually means the gem version is not published or available in the specified gem sources.
  3. Final Answer:

    The specified version of rails is not available in the gem sources -> Option B
  4. Quick Check:

    Missing gem version causes install error [OK]
Hint: Check gem version availability if install fails [OK]
Common Mistakes:
  • Assuming missing source URL causes this error
  • Thinking 'bundle update' fixes missing gem versions
  • Blaming Ruby version without checking gem availability
5. You want to ensure your Ruby project always uses the exact same gem versions on any machine. Which Bundler feature should you use?
hard
A. bundle update to refresh gems
B. gem uninstall to remove old gems
C. Gemfile.lock to lock gem versions
D. bundle exec to run commands

Solution

  1. Step 1: Understand version consistency needs

    To keep gem versions consistent across machines, Bundler uses a lock file that records exact versions installed.
  2. Step 2: Identify the correct Bundler feature

    The Gemfile.lock file stores the exact gem versions after running bundle install.
  3. Step 3: Differentiate other options

    bundle update refreshes gems, gem uninstall removes gems, and bundle exec runs commands in context but doesn't lock versions.
  4. Final Answer:

    Gemfile.lock to lock gem versions -> Option C
  5. Quick Check:

    Gemfile.lock locks versions for consistency [OK]
Hint: Use Gemfile.lock to freeze gem versions across machines [OK]
Common Mistakes:
  • Confusing bundle update with locking versions
  • Thinking bundle exec locks gem versions
  • Ignoring Gemfile.lock file importance
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard