码迷,mamicode.com
首页 > 其他好文 > 详细

how to build a ruby gem

时间:2014-10-23 09:20:40      阅读:136      评论:0      收藏:0      [点我收藏+]

标签: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代码  bubuko.com,布布扣
  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代码  bubuko.com,布布扣
  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       = ‘237178842@qq.com‘  
  9.   s.files       = ["lib/cc_hola.rb"]  
  10.   s.homepage    = ‘https://github.com/chengyuanheng‘  
  11. end  

 

 

4. in your .rb file

 

Java代码  bubuko.com,布布扣
  1. class CcHola  
  2.   def self.hi  
  3.     puts "Hello World!"  
  4.   end  
  5. end  

 

 

5. compiled gem

 

Java代码  bubuko.com,布布扣
  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代码  bubuko.com,布布扣
  1. $ irb  
  2. > require "cc_hola"  
  3. => true  
  4. > CcHola.hi  
  5. Hello World!  
  6. => nil  

 

 

7. release your gem

 

Java代码  bubuko.com,布布扣
  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代码  bubuko.com,布布扣
  1. gem ‘CcHola‘, ‘~> 0.0.0‘  

 

how to build a ruby gem

标签:des   style   blog   http   io   os   ar   java   for   

原文地址:http://www.cnblogs.com/cckkll/p/4044944.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!