Successfully reported this slideshow.

Building a Ruby Gem



Upcoming SlideShare
Web  Security  Programming  I I
Web Security Programming I I
Loading in …3
1 of 9
1 of 9

More Related Content

Related Audiobooks

Free with a 14 day trial from Scribd

See all

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:
  3. 3. Gem Specification spec = do |s| = '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: 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:
  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 >>'foo', 10) => nil
  7. 7. Gem Resources  Rdoc   gem server  http://localhost:8808  publish your gems 
  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!