Giter Club home page Giter Club logo

publish-ruby-gem's Introduction

Guides to make your own gem

Create gemspec file

user.gemspec The gemspec defines what's in the gem, who made it, and the version of gem. It's also your interface to RubyGems.org

Gem::Specification.new do |s|
s.name        = "user_greeting"
s.version     = "0.0.1"
s.summary     = "User Greeting"
s.description = "Greet the user!"
s.authors     = ["Bikash Shrestha"]
s.email       = "[email protected]"
s.files       = Dir["lib/*.rb"]
s.homepage    = "https://rubygems.org/gems/user_greeting"
s.license     = "MIT"
end

Create file lib/user.rb

lib/user.rb

class User
  def self.greet name
     puts "Hello, #{name}"
  end
end

Structure look like the following

.
├── lib
│   └── user.rb
├── .ruby-version
└── user.gemspec

Specify local ruby version

rbenv local 3.1.2 -> this creates .ruby-version file

Create gem

After you've created a gemspec, you can build a ruby gem from it. Then you can install the generated gem locally to test it out.

To build gem run: gem build user.gemspec

To install gem run: gem install user_greeting-0.0.1.gem

Testing your gem

Of course, the smoke test isn't over yet: the final step is to require the gem and use it:

$ irb
irb(main):004:0> require "user"
=> false
irb(main):005:0> User.greet "Bikash Shrestha"
Hello, Bikash Shrestha
=> nil

Publish Gem

To publish your gem, you'll need to create an account on RubyGems.org.

After creating an account, you can push your gem to RubyGems.org using the following commands:

Sign in using gem signin (this will ask your email/username and password on command prompt)

gem push user_greeting-0.0.1.gem

Install your gem : gem install user_greeting

References

Ruby Gem Basics

Specification Ref.

Publish your first ruby gem

Crafting and Publishing Your Ruby Gem

RubyMine: Create & Publish your first Ruby gem

Lunch your own Ruby gem

A step by step guide for building ruby gem

publish-ruby-gem's People

Contributors

sthab-kash avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.