0
0
Rubyprogramming~10 mins

RubyGems repository - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to install a gem named 'rails' using RubyGems.

Ruby
system('gem [1] rails')
Drag options to blanks, or click blank then click option'
Aupdate
Buninstall
Clist
Dinstall
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'update' instead of 'install' will try to update an existing gem.
Using 'uninstall' removes a gem instead of installing it.
2fill in blank
medium

Complete the code to list all installed gems using RubyGems.

Ruby
system('gem [1]')
Drag options to blanks, or click blank then click option'
Alist
Bupdate
Csearch
Dinstall
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'install' tries to add a new gem instead of listing.
Using 'search' looks for gems online, not installed ones.
3fill in blank
hard

Fix the error in the code to search for a gem named 'nokogiri' in the RubyGems repository.

Ruby
system('gem [1] nokogiri')
Drag options to blanks, or click blank then click option'
Ainstall
Bsearch
Clist
Duninstall
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'install' tries to add the gem instead of searching.
Using 'list' only shows installed gems, not available ones.
4fill in blank
hard

Complete the code to create a hash that maps gem names to their versions for gems with version greater than 2.0.

Ruby
gems = gem_list.each_with_object({}) { |(name, version), h| h[name=>version] = version if version [1] '2.0' }
Drag options to blanks, or click blank then click option'
A=>
B>
C<
D:
Attempts:
3 left
💡 Hint
Common Mistakes
Using ':' instead of '=>' for hash mapping.
Using '<' instead of '>' for version comparison.
5fill in blank
hard

Fill all three blanks to create a hash that maps gem names in uppercase to their versions if version is less than '3.0'.

Ruby
result = gems.each_with_object({}) { |(name, version), h| h[name[1] => version] if version [2] '3.0' and name[3] }
Drag options to blanks, or click blank then click option'
A.upcase
B<
C!= ''
D.downcase
Attempts:
3 left
💡 Hint
Common Mistakes
Using '.downcase' instead of '.upcase'.
Using '>=' instead of '<' for version comparison.
Not checking if name is not empty.