`
chengyuanheng
  • 浏览: 19707 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

how to build a ruby gem

    博客分类:
  • gem
 
阅读更多

how to build a ruby gem

 

1. first you will create a user in rubygem.org (https://rubygems.org/) 

 

 

2. create the directory structure like this:

 

$ tree  
.  
├── cc_hola.gemspec  
└── lib  
    └── cc_hola.rb  

  

   you can use any name but you must keep consistency

 

 

3. in your .gemspec file

 

Gem::Specification.new do |s|
  s.name        = 'CcHola'
  s.version     = '0.0.0'
  s.date        = '2014-10-20'
  s.summary     = "A ruby gem build test!"
  s.description = "A ruby gem build test!"
  s.authors     = ["cckkll"]
  s.email       = '237178842@qq.com'
  s.files       = ["lib/cc_hola.rb"]
  s.homepage    = 'https://github.com/chengyuanheng'
end

 

 

4. in your .rb file

 

class CcHola
  def self.hi
    puts "Hello World!"
  end
end

 

 

5. compiled gem

 

$ 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
1 gem installed 

 

 

 6. test your gem

 

$ irb
> require "cc_hola"
=> true
> CcHola.hi
Hello World!
=> nil

 

 

7. release your gem

 

$ curl -u cckkll https://rubygems.org/api/v1/api_key.yaml >~/.gem/credentials
Enter host password for user 'cckkll':

$ 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 by

 

gem 'CcHola', '~> 0.0.0'

 

分享到:
评论
2 楼 chengyuanheng 2014-11-06  
好吧 ,已改!
1 楼 心静如止水 2014-11-04  
"creata"写错了,第一句话

相关推荐

Global site tag (gtag.js) - Google Analytics