Bird
0
0

You want to add a gem only for Ruby version 3.1 or higher in your Gemfile. Which is the correct way?

hard📝 Application Q9 of 15
Ruby - Gems and Bundler
You want to add a gem only for Ruby version 3.1 or higher in your Gemfile. Which is the correct way?
Agem 'bootsnap' if RUBY_VERSION >= '3.1'
Bgem 'bootsnap', ruby: '>= 3.1'
Cruby '>= 3.1' gem 'bootsnap'
Dgroup :ruby_3_1 do gem 'bootsnap' end
Step-by-Step Solution
Solution:
  1. Step 1: Understand conditional gem inclusion in Gemfile

    Gemfile is Ruby code, so use if RUBY_VERSION >= '3.1' to conditionally add gems.
  2. Step 2: Evaluate each option

    A correctly uses Ruby conditional. B uses invalid gem option 'ruby:'. C sets project Ruby requirement (fails if not met). D uses invalid group.
  3. Final Answer:

    gem 'bootsnap' if RUBY_VERSION >= '3.1' -> Option A
  4. Quick Check:

    Ruby if for version-specific gems [OK]
Quick Trick: Use Ruby if conditionals for version-specific gems [OK]
Common Mistakes:
  • Using top-level ruby for per-gem conditional
  • Invalid gem options like ruby:
  • Creating fake groups for Ruby versions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes