首页 > 代码库 > how to build a ruby gem
how to build a ruby gem
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代码
- $ tree
- .
- ├── cc_hola.gemspec
- └── lib
- └── cc_hola.rb
you can use any name but you must keep consistency
3. in your .gemspec file
Java代码
- 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
Java代码
- class CcHola
- def self.hi
- puts "Hello World!"
- end
- end
5. compiled gem
Java代码
- $ 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代码
- $ irb
- > require "cc_hola"
- => true
- > CcHola.hi
- Hello World!
- => nil
7. release your gem
Java代码
- $ 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
Java代码
- gem ‘CcHola‘, ‘~> 0.0.0‘
how to build a ruby gem
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。