DEV Community

Cover image for Creating a Gem
Marcelo Junior
Marcelo Junior

Posted on

Creating a Gem

Creating a Gem

After compiling and testing our C Extension for Ruby, we can now create a Gem!
First, we should create some folders to organize the project.

See below:
Image description

Second, create the file lib/foo.rb:

require 'foo/foo' 
Enter fullscreen mode Exit fullscreen mode

(You can create other classes inside this file if you desire.)

And finally, create the file foo.gemspec inside the root of the project:

Gem::Specification.new "foo", "0.0.0" do |s| s.summary = "A SUMMARY" s.description = "A DESCRIPTION" s.authors = ["author"] s.email = "email@example.com" s.files = %w[lib/foo.rb lib/foo/foo.so] s.homepage = "http://anylink.com" s.license = "MIT" s.extensions = %w[ext/foo/extconf.rb] end 
Enter fullscreen mode Exit fullscreen mode

Now you can run on the root project:

gem build foo.gemspec gem install foo 
Enter fullscreen mode Exit fullscreen mode

To test the gem you can open the irb and past this code:

require 'foo' Greeting.hello # hello! 
Enter fullscreen mode Exit fullscreen mode

🎉 Yeahhhh!!! We have a Gem!!! 🎉

Top comments (0)