Successfully reported this slideshow.
Activate your 14 day free trial to unlock unlimited reading.
Building a Gem
write some Ruby code that you want to make
available as a gem
creating a gem specification file (mygem.gemspec),
which is Ruby code
running gem build mygem.gemspec to create
the gem file (mygem-2.1.gem)
spec = Gem::Specification.new do |s|
s.name = 'rfoo'
s.version = '1.0'
s.summary = 'example gem'
s.files = ['myfile.rb', 'README’,'LICENSE.txt']
Source goes into a /lib directory
Then you would put your specs into spec/lib
More info: http://rubygems.rubyforge.org/rubygems-
Always Include a License
MIT License – typically used for Ruby code
Copyright (c) <year> <copyright holders>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
More info on this and other licenses: http://www.opensource.org/
Building & Installing the Gem
gem build my_gem.gemspec
--> now you have a gem file: my_gem-0.0.1.gem
gem list my_gem
--> but you don't have access to the gem yet, you need
to install it
gem install my_gem-0.0.1.gem
gem list my_gem
Using the Gem We Built
>> load ’my_file'
LoadError: no such file to load -- test_data
from (irb):1:in `load'
>> require ’my_file'
>> MyThing.do('foo', 10)
publish your gems
Give me more Ruby (and friends)!
Stay tuned to the Ruby-6 list for info about:
Beginning & Advanced Ruby classes
Free design pattern study group
T.A. opportunity: If you’d like to take this class again
(for free!) you can volunteer to setup/cleanup and
help students. Just email us!