Challenge - 5 Problems
Bundle Exec Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Ruby code using bundle exec?
Consider you have a Gemfile specifying gem 'colorize', version '0.8.1'. You run the following Ruby script with
bundle exec ruby script.rb:Ruby
require 'colorize' puts 'Hello'.colorize(:red)
Attempts:
2 left
💡 Hint
Using bundle exec ensures gems from Gemfile are loaded correctly.
✗ Incorrect
Using bundle exec runs the script with the gems specified in the Gemfile, so 'colorize' gem version 0.8.1 is loaded and the string prints in red.
🧠 Conceptual
intermediate1:30remaining
Why use
bundle exec when running Ruby scripts?Choose the best reason why
bundle exec is used before running Ruby commands.Attempts:
2 left
💡 Hint
Think about gem versions and conflicts.
✗ Incorrect
bundle exec runs commands using the gems and versions locked in the Gemfile.lock, preventing conflicts with other installed gems.🔧 Debug
advanced2:00remaining
What error occurs when running a Ruby script without
bundle exec?Given a project with a Gemfile specifying 'nokogiri' version 1.12.5, running
ruby script.rb (without bundle exec) causes an error. What is the most likely error?Ruby
require 'nokogiri' puts Nokogiri::VERSION
Attempts:
2 left
💡 Hint
Without bundle exec, Ruby might not find the gem installed for this project.
✗ Incorrect
Without bundle exec, Ruby uses system gems which may not include the required version or gem, causing LoadError.
📝 Syntax
advanced1:00remaining
Which command correctly runs a Rake task using bundle exec?
You want to run the Rake task named 'db:migrate' using bundle exec. Which command is correct?
Attempts:
2 left
💡 Hint
bundle exec should come before the command you want to run.
✗ Incorrect
The correct syntax is 'bundle exec' followed by the command and its arguments.
🚀 Application
expert3:00remaining
How many gems are loaded when running
bundle exec ruby script.rb with this Gemfile?Given this Gemfile content:
source 'https://rubygems.org' gem 'rails', '7.0.4' gem 'puma', '~> 5.0' gem 'nokogiri', '1.12.5'And
bundle install was run successfully. How many gems (including dependencies) are loaded when running bundle exec ruby script.rb?Attempts:
2 left
💡 Hint
Bundler sets up the environment but does not automatically load (require) the gems; only those required in the script are loaded.
✗ Incorrect
`bundle exec ruby script.rb` uses Bundler to set the correct LOAD_PATH for gems in Gemfile.lock. Gems are only loaded when explicitly required in script.rb, ensuring the correct versions and their dependencies are used.