DEV Community

Cover image for Creating a Gem
Marcelo Junior
Marcelo Junior

Posted on

3

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!!! 🎉

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs