0
0
Rubyprogramming~20 mins

RubyGems repository - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
RubyGems 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 RubyGems command?
Consider the following Ruby code that uses RubyGems to list installed gems. What will be printed?
Ruby
require 'rubygems'
puts Gem::Specification.find_all.map(&:name).sort.first(3).join(', ')
AA comma-separated list of the first three gem names alphabetically installed on the system
BA list of all gem names installed, unsorted
CAn error because Gem::Specification.find_all is not a valid method
DAn empty string because no gems are found
Attempts:
2 left
💡 Hint
Gem::Specification.find_all returns all installed gems as objects. Mapping &:name extracts their names.
🧠 Conceptual
intermediate
1:30remaining
Which RubyGems command installs a gem and its dependencies?
You want to install a gem named 'nokogiri' along with all its dependencies. Which command should you use?
Agem uninstall nokogiri
Bgem install nokogiri
Cgem build nokogiri
Dgem fetch nokogiri
Attempts:
2 left
💡 Hint
Installing a gem downloads and installs it with dependencies.
Predict Output
advanced
2:00remaining
What error does this RubyGems code raise?
What error will this Ruby code raise when run?
Ruby
require 'rubygems'
Gem::Specification.find_by_name('nonexistent_gem')
AGem::MissingSpecError
BNoMethodError
CArgumentError
DRuntimeError
Attempts:
2 left
💡 Hint
find_by_name raises an error if the gem is not found.
🚀 Application
advanced
2:30remaining
How to programmatically list all versions of a gem installed?
You want to write Ruby code that lists all installed versions of the gem 'rake'. Which code snippet correctly does this?
AGem::Specification.list_versions('rake')
BGem::Specification.find_by_name('rake').version.to_s
CGem::Specification.latest_version('rake')
DGem::Specification.find_all_by_name('rake').map(&:version).map(&:to_s)
Attempts:
2 left
💡 Hint
find_all_by_name returns all specs matching the gem name.
🔧 Debug
expert
3:00remaining
Why does this RubyGems code fail to install a gem?
This Ruby code tries to install the 'json' gem but fails with an error. What is the cause?
Ruby
require 'rubygems'
require 'rubygems/installer'
installer = Gem::Installer.new('json-2.6.1.gem')
installer.install
AGem::Installer requires a block to run
BThe gem 'json' is already installed, so install fails
CThe gem file path 'json-2.6.1.gem' is missing or incorrect
DGem::Installer cannot install gems programmatically
Attempts:
2 left
💡 Hint
Check if the gem file exists at the given path.