How to build a ruby gem
1. First you will creata a user in rubygem.org (https://rubygems.org /)
2. Create the directory structure like this:
Java code
- $ Tree
- .
- ── Cc_hola.gemspec
- ── Lib
- ── Cc_hola.rb
You can use any name but you must keep consistency
3. In your. gemspec File
Java code
- GEM: specification. New do | S |
- S. Name = 'cchola'
- S. Version = '0. 0.0'
- S. Date = '2017-10-20'
- S. Summary = "a ruby gem build test! "
- S. Description = "a ruby gem build test! "
- S. Authors = ["mongokll"]
- S. Email = '[email protected]'
- S. Files = ["lib/cc_hola.rb"]
- S. Homepage = 'https: // github.com/chengyuanheng'
- End
4. In your. RB File
Java code
- Class cchola
- Def self. Hi
- Puts "Hello world! "
- End
- End
5. Compiled gem
Java code
- $ Gem build cc_hola.gemspec
- Successfully built rubygem
- Name: cchola
- Version: 0.0.0
- File: CcHola-0.0.0.gem
- $ Gem install ccHola-0.0.0.gem
- Successfully installed CcHola-0.0.0
- <Span> 1 gem installed </span>
6. Test your gem
Java code
- $ IRB
- > Require "cc_hola"
- => True
- > Cchola. Hi
- Hello world!
- => Nil
7. Release your gem
Java code
- $ Curl-u cckkll https://rubygems.org/api/v1/api_key.yaml> ~ /. Gem/Credentials
- Enter host password for user 'your kll ':
- $ Gem push CcHola-0.0.0.gem
- Pushing gem to https://rubygems.org...
- Successfully registered GEM: cchola (0.0.0)
You will find it in your rubygems account and all people can use it
Java code
- Gem 'cchola ',' ~> 0.0.0'
How to build a ruby gem