Create a basic file structure.
Ex:
mkdir test_gem #pasta raiz
cd test_gem
mkdir lib
Create a file with the extension .gemspec inside the root of your project.
Ex:
"test_gem.gemspec"
Then add some specifications to create a valid gem.
Ex:
Gem::Specification.new do |s|
s.name = 'test_gem'
s.version = '2.1.0'
s.authors = ["Quêmia"]
s.email = ["quemia@hotmail.com"]
s.summary = "This is an example!"
s.description = %q[My first gem!]
s.homepage = "http://github.com"
s.license = "MIT"
s.files = ["lib/test_gem.rb"]
end
Create a Ruby file inside the lib subfolder, this is the only file that must exist in the root of lib. Add the code that the gem should have.
Ex:
cat > test_gem.rb
module AwesomeGem
class WhoIs
def self.awesome?
puts "YOU ARE AWESOME!!"
end
end
end
Generate the gem file. The command will create the gem and produce a gem file that will include the version number in the file name.
Ex:
$ gem build awesome_gem.gemspec
Successfully built RubyGem
Name: test_gem
Version: 2.1.0
File: test_gem-2.01.0.gem
You should see the following output and some notices about missing attributes.
Install the gem.
Ex:
gem install test_gem-2.01.0.gem
You should get the following output:
Successfully installed awesome_gem-0.0.0
1 gem installed
Installing ri documentation for awesome_gem-0.0.0...
Installing RDoc documentation for awesome_gem-0.0.0...
Test the function:
Ex:
% irb
>> require 'test_gem.rb'
=> true
>> AwesomeGem :: WhoIs.awesome?
YOU ARE AWESOME!