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.
Second, create the file lib/foo.rb
:
require 'foo/foo'
(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
Now you can run on the root project:
gem build foo.gemspec gem install foo
To test the gem you can open the irb
and past this code:
require 'foo' Greeting.hello # hello!
🎉 Yeahhhh!!! We have a Gem!!! 🎉
Top comments (0)