0
0
Rubyprogramming~20 mins

Creating a gem basics in Ruby - Practice Exercises

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Ruby Gem Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1:30remaining
What is the output of this gemspec version code?
Consider this snippet from a gemspec file defining the gem version. What will be printed when running this Ruby code?
Ruby
module MyGem
  VERSION = "1.2.3"
end

puts MyGem::VERSION
AError: uninitialized constant MyGem
BMyGem::VERSION
Cversion 1.2.3
D1.2.3
Attempts:
2 left
💡 Hint
Look at how constants are accessed inside modules in Ruby.
🧠 Conceptual
intermediate
1:00remaining
Which file is essential to define a Ruby gem's metadata?
When creating a Ruby gem, which file must you create to specify the gem's name, version, summary, and authors?
AGemfile
Bgemspec
CREADME.md
DRakefile
Attempts:
2 left
💡 Hint
This file ends with .gemspec and is used by RubyGems.
🔧 Debug
advanced
2:00remaining
Why does this gemspec raise an error?
Look at this gemspec snippet. Why does it raise a SyntaxError? s.name = "my_gem" s.version = 0.1.0 s.summary = "A sample gem"
Ruby
Gem::Specification.new do |s|
  s.name = "my_gem"
  s.version = 0.1.0
  s.summary = "A sample gem"
end
AVersion must be a string, not a float or number
BMissing comma between version numbers
CThe block variable s is not defined
DThe gemspec must use single quotes for strings
Attempts:
2 left
💡 Hint
Look carefully at the version assignment syntax.
📝 Syntax
advanced
1:30remaining
Which option correctly defines a gem's authors array in gemspec?
Select the correct syntax to assign multiple authors in a gemspec file.
Ruby
Gem::Specification.new do |s|
  s.authors = ???
end
A["Alice", "Bob"]
B"Alice, Bob"
C{Alice, Bob}
D("Alice", "Bob")
Attempts:
2 left
💡 Hint
Authors should be an array of strings.
🚀 Application
expert
2:00remaining
How many files are created by default when running `bundle gem my_gem`?
When you run the command `bundle gem my_gem` to create a new gem skeleton, how many files are created by default (excluding hidden files)?
A10
B5
C8
D12
Attempts:
2 left
💡 Hint
Count files like gemspec, README, lib files, and test files generated.