C L A S S 6
Building a Gem
Building a Gem
 write some Ruby code that you want to make
available as a gem
 creating a gem specification file (mygem....
Gem Specification
spec = Gem::Specification.new do |s|
s.name = 'rfoo'
s.version = '1.0'
s.summary = 'example gem'
s.files...
Always Include a License
MIT License – typically used for Ruby code
Copyright (c) <year> <copyright holders>
Permission is...
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
--> b...
Using the Gem We Built
$ irb
>> load ’my_file'
LoadError: no such file to load -- test_data
from (irb):1:in `load'
from (i...
Gem Resources
 Rdoc
 http://rdoc.sourceforge.net/doc/index.html
 gem server
 http://localhost:8808
 publish your gems...
Give me more Ruby (and friends)!
 Stay tuned to the Ruby-6 list for info about:
 Rails class
 Beginning & Advanced Ruby...
T I M E T O P A R T Y .
Thank You!
Upcoming SlideShare
Loading in …5
×

Building a Ruby Gem

3,848 views

Published on

Building a Ruby Gem by Liah Hansen and Sarah Allen

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,848
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
16
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Building a Ruby Gem

  1. 1. C L A S S 6 Building a Gem
  2. 2. 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)  More info: http://docs.rubygems.org/read/chapter/5
  3. 3. Gem Specification spec = Gem::Specification.new do |s| s.name = 'rfoo' s.version = '1.0' s.summary = 'example gem' s.files = ['myfile.rb', 'README’,'LICENSE.txt'] end  Source goes into a /lib directory  Then you would put your specs into spec/lib  More info: http://rubygems.rubyforge.org/rubygems- update/Gem/Specification.html
  4. 4. 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 THE SOFTWARE. More info on this and other licenses: http://www.opensource.org/
  5. 5. 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
  6. 6. Using the Gem We Built $ irb >> load ’my_file' LoadError: no such file to load -- test_data from (irb):1:in `load' from (irb):1 >> require ’my_file' => true >> MyThing.do('foo', 10) => nil
  7. 7. Gem Resources  Rdoc  http://rdoc.sourceforge.net/doc/index.html  gem server  http://localhost:8808  publish your gems  http://gemcutter.org/
  8. 8. Give me more Ruby (and friends)!  Stay tuned to the Ruby-6 list for info about:  Rails class  Beginning & Advanced Ruby classes  Javascript class  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!
  9. 9. T I M E T O P A R T Y . Thank You!

×