Challenge - 5 Problems
Ruby Gem Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1: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
Attempts:
2 left
💡 Hint
Look at how constants are accessed inside modules in Ruby.
✗ Incorrect
The constant VERSION inside the module MyGem is accessed with MyGem::VERSION, which returns the string "1.2.3". The puts prints this string.
🧠 Conceptual
intermediate1: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?
Attempts:
2 left
💡 Hint
This file ends with .gemspec and is used by RubyGems.
✗ Incorrect
The gemspec file contains metadata about the gem such as its name, version, authors, and summary. Gemfile is for dependencies, Rakefile for tasks, README.md for documentation.
🔧 Debug
advanced2: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
Attempts:
2 left
💡 Hint
Look carefully at the version assignment syntax.
✗ Incorrect
The version must be a string like "0.1.0". Writing 0.1.0 without quotes is invalid Ruby syntax and causes a SyntaxError.
📝 Syntax
advanced1: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
Attempts:
2 left
💡 Hint
Authors should be an array of strings.
✗ Incorrect
The authors attribute expects an array of strings. Option A uses square brackets to create an array. Option A is a single string, C and D are invalid Ruby syntax for arrays.
🚀 Application
expert2: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)?
Attempts:
2 left
💡 Hint
Count files like gemspec, README, lib files, and test files generated.
✗ Incorrect
By default, `bundle gem` creates around 8 files including the gemspec, README.md, Rakefile, lib directory with main file, and test files.