Bird
0
0

Which of the following is the correct syntax to specify a gem with a version constraint in a Gemfile?

easy📝 Syntax Q3 of 15
Ruby - Gems and Bundler
Which of the following is the correct syntax to specify a gem with a version constraint in a Gemfile?
Agem 'rails' => '6.1.0'
Bgem rails version 6.1.0
Cgem 'rails' version: '6.1.0'
Dgem 'rails', '~> 6.1.0'
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct Gemfile gem declaration syntax

    Gems are declared with gem 'name', 'version' format.
  2. Step 2: Identify the correct version constraint syntax

    ~> 6.1.0 means compatible with 6.1.x versions.
  3. Final Answer:

    gem 'rails', '~> 6.1.0' -> Option D
  4. Quick Check:

    Gemfile version syntax = gem 'name', '~> version' [OK]
Quick Trick: Use gem 'name', '~> version' for version constraints [OK]
Common Mistakes:
  • Using incorrect hash rocket or keyword syntax
  • Omitting quotes around gem name
  • Writing version without comma

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes