0
0
Rubyprogramming~20 mins

Why gem management matters in Ruby - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Gem Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output when requiring gems without version control?
Consider a Ruby project that requires the 'json' gem. If the system has multiple versions of 'json' installed, what will be the output of the following code when run without specifying a gem version?
Ruby
require 'json'
puts JSON.generate({hello: 'world'})
A{"hello":"world"}
BLoadError: cannot load such file -- json
CTypeError: no implicit conversion of Symbol into String
DSyntaxError: unexpected token
Attempts:
2 left
💡 Hint
Think about what happens when Ruby loads the default gem version.
🧠 Conceptual
intermediate
1:30remaining
Why lock gem versions in a Gemfile?
Why is it important to lock gem versions in a Gemfile when managing Ruby projects?
ATo reduce the size of the project by removing unused gems.
BTo allow gems to update automatically to the latest versions without restrictions.
CTo ensure consistent gem versions across different environments and avoid unexpected bugs.
DTo speed up the Ruby interpreter during runtime.
Attempts:
2 left
💡 Hint
Think about what happens if different developers use different gem versions.
🔧 Debug
advanced
2:30remaining
Identify the error caused by missing gem version specification
Given the following Gemfile and Ruby code, what error will occur when running the code if the gem version is not specified and multiple versions are installed? Gemfile: gem 'nokogiri' Ruby code: require 'nokogiri' puts Nokogiri::HTML('

Hello

').text
Ruby
require 'nokogiri'
puts Nokogiri::HTML('<h1>Hello</h1>').text
ALoadError: cannot load such file -- nokogiri
BNoMethodError: undefined method 'HTML' for Nokogiri:Module
CArgumentError: wrong number of arguments
DOutputs 'Hello' without error
Attempts:
2 left
💡 Hint
Consider what happens if the gem loads correctly.
📝 Syntax
advanced
1:30remaining
Which Gemfile syntax correctly specifies a gem version?
Select the correct syntax to specify version 2.1.0 of the 'rails' gem in a Gemfile.
Agem 'rails', '2.1.0'
Bgem rails, version: '2.1.0'
Cgem 'rails' version '2.1.0'
Dgem 'rails' => '2.1.0'
Attempts:
2 left
💡 Hint
Look for the correct Ruby method argument syntax.
🚀 Application
expert
3:00remaining
How does Bundler ensure consistent gem versions across environments?
Bundler uses a special file to lock gem versions. What is the name of this file and how does Bundler use it to maintain consistency?
AGemfile.lock; Bundler ignores this file and installs latest gem versions always.
BGemfile.lock; Bundler reads this file to install exact gem versions specified during bundle install.
CGemfile; Bundler uses this file to lock gem versions and ignores Gemfile.lock.
Dbundle.lock; Bundler uses this file to cache gem downloads but not versions.
Attempts:
2 left
💡 Hint
Think about the file Bundler creates after installing gems.