0
0
Rubyprogramming~20 mins

Bundle exec for isolated execution in Ruby - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Bundle Exec 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 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)
ARaises LoadError because colorize gem is not found
BPrints 'Hello' without color
CPrints 'Hello' in red color in the terminal
DSyntaxError due to incorrect gem usage
Attempts:
2 left
💡 Hint
Using bundle exec ensures gems from Gemfile are loaded correctly.
🧠 Conceptual
intermediate
1:30remaining
Why use bundle exec when running Ruby scripts?
Choose the best reason why bundle exec is used before running Ruby commands.
ATo run the command with gems specified in the Gemfile, avoiding conflicts with system gems
BTo speed up Ruby script execution by caching gems
CTo run the script without loading any gems
DTo automatically update all gems before running the script
Attempts:
2 left
💡 Hint
Think about gem versions and conflicts.
🔧 Debug
advanced
2: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
ASyntaxError: unexpected end-of-input
BRuntimeError: gem version mismatch
CNoMethodError: undefined method 'VERSION' for Nokogiri:Module
DLoadError: cannot load such file -- nokogiri
Attempts:
2 left
💡 Hint
Without bundle exec, Ruby might not find the gem installed for this project.
📝 Syntax
advanced
1: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?
Abundle exec rake db:migrate
Brake bundle exec db:migrate
Cbundle rake exec db:migrate
Dexec bundle rake db:migrate
Attempts:
2 left
💡 Hint
bundle exec should come before the command you want to run.
🚀 Application
expert
3: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?
AExactly 3 gems only
BOnly the gems explicitly required in script.rb
CAt least 3 gems plus all their dependencies
DNo gems are loaded automatically
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.