How to build a ruby gem

Source: Internet
Author: User

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
  1. $ Tree
  2. .
  3. ── Cc_hola.gemspec
  4. ── Lib
  5. ── Cc_hola.rb

You can use any name but you must keep consistency

 

 

3. In your. gemspec File

 

Java code
  1. GEM: specification. New do | S |
  2. S. Name = 'cchola'
  3. S. Version = '0. 0.0'
  4. S. Date = '2017-10-20'
  5. S. Summary = "a ruby gem build test! "
  6. S. Description = "a ruby gem build test! "
  7. S. Authors = ["mongokll"]
  8. S. Email = '[email protected]'
  9. S. Files = ["lib/cc_hola.rb"]
  10. S. Homepage = 'https: // github.com/chengyuanheng'
  11. End

 

 

4. In your. RB File

 

Java code
  1. Class cchola
  2. Def self. Hi
  3. Puts "Hello world! "
  4. End
  5. End

 

5. Compiled gem

 

Java code
  1. $ Gem build cc_hola.gemspec
  2. Successfully built rubygem
  3. Name: cchola
  4. Version: 0.0.0
  5. File: CcHola-0.0.0.gem
  6. $ Gem install ccHola-0.0.0.gem
  7. Successfully installed CcHola-0.0.0
  8. <Span> 1 gem installed </span>

 

 

6. Test your gem

 

Java code
  1. $ IRB
  2. > Require "cc_hola"
  3. => True
  4. > Cchola. Hi
  5. Hello world!
  6. => Nil

 

 

7. Release your gem

 

Java code
  1. $ Curl-u cckkll https://rubygems.org/api/v1/api_key.yaml> ~ /. Gem/Credentials
  2. Enter host password for user 'your kll ':
  3. $ Gem push CcHola-0.0.0.gem
  4. Pushing gem to https://rubygems.org...
  5. Successfully registered GEM: cchola (0.0.0)

 

 

You will find it in your rubygems account and all people can use it

 

Java code
  1. Gem 'cchola ',' ~> 0.0.0'

 

How to build a ruby gem

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.