how to build a ruby gem

來源:互聯網
上載者:User

標籤:des   style   blog   http   io   os   ar   java   for   

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代碼  
  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代碼  
  1. Gem::Specification.new do |s|  
  2.   s.name        = ‘CcHola‘  
  3.   s.version     = ‘0.0.0‘  
  4.   s.date        = ‘2014-10-20‘  
  5.   s.summary     = "A ruby gem build test!"  
  6.   s.description = "A ruby gem build test!"  
  7.   s.authors     = ["cckkll"]  
  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代碼  
  1. class CcHola  
  2.   def self.hi  
  3.     puts "Hello World!"  
  4.   end  
  5. end  

 

 

5. compiled gem

 

Java代碼  
  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.   
  7. $ gem install ccHola-0.0.0.gem  
  8. Successfully installed CcHola-0.0.0  
  9. <span>1 gem installed</span>   

 

 

 6. test your gem

 

Java代碼  
  1. $ irb  
  2. > require "cc_hola"  
  3. => true  
  4. > CcHola.hi  
  5. Hello World!  
  6. => nil  

 

 

7. release your gem

 

Java代碼  
  1. $ curl -u cckkll https://rubygems.org/api/v1/api_key.yaml >~/.gem/credentials  
  2. Enter host password for user ‘cckkll‘:  
  3.   
  4. $ gem push CcHola-0.0.0.gem   
  5. Pushing gem to https://rubygems.org...  
  6. Successfully registered gem: CcHola (0.0.0)  

 

 

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

 

Java代碼  
  1. gem ‘CcHola‘, ‘~> 0.0.0‘  

 

how to build a ruby gem

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.