Building a Ruby Gem

Sarah Allen
Sarah AllenInnovation Catalyst
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.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
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
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/
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
$ 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
Gem Resources
 Rdoc
 http://rdoc.sourceforge.net/doc/index.html
 gem server
 http://localhost:8808
 publish your gems
 http://gemcutter.org/
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!
T I M E T O P A R T Y .
Thank You!
1 of 9

Recommended

Web Security Programming I I by
Web  Security  Programming  I IWeb  Security  Programming  I I
Web Security Programming I IPavu Jas
456 views20 slides
Intro to Wordpress Security by
Intro to Wordpress SecurityIntro to Wordpress Security
Intro to Wordpress SecurityChris Dodds
411 views16 slides
Memcache Injection (Hacktrick'15) by
Memcache Injection (Hacktrick'15)Memcache Injection (Hacktrick'15)
Memcache Injection (Hacktrick'15)Ömer Çıtak
1.8K views24 slides
Sql Injection Paper by
Sql Injection PaperSql Injection Paper
Sql Injection PaperAung Khant
428 views4 slides
[1.2] Трюки при анализе защищенности веб приложений – продвинутая версия - С... by
[1.2] Трюки при анализе защищенности веб приложений – продвинутая версия - С...[1.2] Трюки при анализе защищенности веб приложений – продвинутая версия - С...
[1.2] Трюки при анализе защищенности веб приложений – продвинутая версия - С...OWASP Russia
2K views61 slides
Bünyamin Demir - Secure YourApp by
Bünyamin Demir - Secure YourAppBünyamin Demir - Secure YourApp
Bünyamin Demir - Secure YourAppCypSec - Siber Güvenlik Konferansı
988 views30 slides

More Related Content

Similar to Building a Ruby Gem

Install Guide by
Install GuideInstall Guide
Install GuideSantosh Kiran Beyagudem
436 views13 slides
Rails onCpanel by
Rails onCpanelRails onCpanel
Rails onCpanelWeldys Santos
583 views29 slides
grate techniques by
grate techniquesgrate techniques
grate techniquesjunaid novapex
151 views5 slides
Guarding Your Code Against Bugs with Continuous Testing by
Guarding Your Code Against Bugs with Continuous TestingGuarding Your Code Against Bugs with Continuous Testing
Guarding Your Code Against Bugs with Continuous TestingEric Hogue
719 views108 slides
RoR guide_p1 by
RoR guide_p1RoR guide_p1
RoR guide_p1Brady Cheng
931 views18 slides
Basic Malware Analysis by
Basic Malware AnalysisBasic Malware Analysis
Basic Malware AnalysisAlbert Hui
4.4K views20 slides

Similar to Building a Ruby Gem(20)

Guarding Your Code Against Bugs with Continuous Testing by Eric Hogue
Guarding Your Code Against Bugs with Continuous TestingGuarding Your Code Against Bugs with Continuous Testing
Guarding Your Code Against Bugs with Continuous Testing
Eric Hogue719 views
Basic Malware Analysis by Albert Hui
Basic Malware AnalysisBasic Malware Analysis
Basic Malware Analysis
Albert Hui4.4K views
selenium-2-mobile-web-testing by hugs
selenium-2-mobile-web-testingselenium-2-mobile-web-testing
selenium-2-mobile-web-testing
hugs8.2K views
Jboss Exploit by drkimsky
Jboss ExploitJboss Exploit
Jboss Exploit
drkimsky3.5K views
Ruby on Windows - HOW TO install and set up by Tim Golden
Ruby on Windows - HOW TO install and set upRuby on Windows - HOW TO install and set up
Ruby on Windows - HOW TO install and set up
Tim Golden2.1K views
003__MACOSX._003002__MACOSX._002SES_OSS.DS_.docx by smithhedwards48727
003__MACOSX._003002__MACOSX._002SES_OSS.DS_.docx003__MACOSX._003002__MACOSX._002SES_OSS.DS_.docx
003__MACOSX._003002__MACOSX._002SES_OSS.DS_.docx
Protractor Testing Automation Tool Framework / Jasmine Reporters by Haitham Refaat
Protractor Testing Automation Tool Framework / Jasmine ReportersProtractor Testing Automation Tool Framework / Jasmine Reporters
Protractor Testing Automation Tool Framework / Jasmine Reporters
Haitham Refaat559 views
Capifony. Minsk PHP MeetUp #11 by Yury Pliashkou
Capifony. Minsk PHP MeetUp #11Capifony. Minsk PHP MeetUp #11
Capifony. Minsk PHP MeetUp #11
Yury Pliashkou1.2K views
Ruby windows by Tim Golden
Ruby windowsRuby windows
Ruby windows
Tim Golden441 views
Mobile Testing with Selenium 2 by Jason Huggins by Sauce Labs
Mobile Testing with Selenium 2 by Jason HugginsMobile Testing with Selenium 2 by Jason Huggins
Mobile Testing with Selenium 2 by Jason Huggins
Sauce Labs8.8K views
Building Microservices with Helidon: Oracle's New Java Microservices Framework by Michael Redlich
Building Microservices with Helidon:  Oracle's New Java Microservices FrameworkBuilding Microservices with Helidon:  Oracle's New Java Microservices Framework
Building Microservices with Helidon: Oracle's New Java Microservices Framework
Michael Redlich274 views

More from Sarah Allen

Internet security: a landscape of unintended consequences by
Internet security: a landscape of unintended consequencesInternet security: a landscape of unintended consequences
Internet security: a landscape of unintended consequencesSarah Allen
439 views49 slides
RTMP: how did we get to now? (Demuxed 2019) by
RTMP: how did we get to now? (Demuxed 2019)RTMP: how did we get to now? (Demuxed 2019)
RTMP: how did we get to now? (Demuxed 2019)Sarah Allen
405 views32 slides
Communication is a Technical Skill by
Communication is a Technical SkillCommunication is a Technical Skill
Communication is a Technical SkillSarah Allen
2.6K views73 slides
Improving Federal Government Services by
Improving Federal Government ServicesImproving Federal Government Services
Improving Federal Government ServicesSarah Allen
1.1K views86 slides
Transparency Wins by
Transparency WinsTransparency Wins
Transparency WinsSarah Allen
1.2K views94 slides
A Short History of Computers by
A Short History of ComputersA Short History of Computers
A Short History of ComputersSarah Allen
1.1K views15 slides

More from Sarah Allen(20)

Internet security: a landscape of unintended consequences by Sarah Allen
Internet security: a landscape of unintended consequencesInternet security: a landscape of unintended consequences
Internet security: a landscape of unintended consequences
Sarah Allen439 views
RTMP: how did we get to now? (Demuxed 2019) by Sarah Allen
RTMP: how did we get to now? (Demuxed 2019)RTMP: how did we get to now? (Demuxed 2019)
RTMP: how did we get to now? (Demuxed 2019)
Sarah Allen405 views
Communication is a Technical Skill by Sarah Allen
Communication is a Technical SkillCommunication is a Technical Skill
Communication is a Technical Skill
Sarah Allen2.6K views
Improving Federal Government Services by Sarah Allen
Improving Federal Government ServicesImproving Federal Government Services
Improving Federal Government Services
Sarah Allen1.1K views
Transparency Wins by Sarah Allen
Transparency WinsTransparency Wins
Transparency Wins
Sarah Allen1.2K views
A Short History of Computers by Sarah Allen
A Short History of ComputersA Short History of Computers
A Short History of Computers
Sarah Allen1.1K views
Making Software Fun by Sarah Allen
Making Software FunMaking Software Fun
Making Software Fun
Sarah Allen1.6K views
Power of Transparency by Sarah Allen
Power of TransparencyPower of Transparency
Power of Transparency
Sarah Allen1.5K views
Designing for Fun by Sarah Allen
Designing for FunDesigning for Fun
Designing for Fun
Sarah Allen3.4K views
Ruby in the US Government for Ruby World Conference by Sarah Allen
Ruby in the US Government for Ruby World ConferenceRuby in the US Government for Ruby World Conference
Ruby in the US Government for Ruby World Conference
Sarah Allen1.4K views
Identities of Dead People by Sarah Allen
Identities of Dead PeopleIdentities of Dead People
Identities of Dead People
Sarah Allen2K views
3 Reasons Not to Use Ruby by Sarah Allen
3 Reasons Not to Use Ruby 3 Reasons Not to Use Ruby
3 Reasons Not to Use Ruby
Sarah Allen1.3K views
Ruby Nation: Why no haz Ruby? by Sarah Allen
Ruby Nation: Why no haz Ruby?Ruby Nation: Why no haz Ruby?
Ruby Nation: Why no haz Ruby?
Sarah Allen947 views
Why no ruby in gov? by Sarah Allen
Why no ruby in gov?Why no ruby in gov?
Why no ruby in gov?
Sarah Allen1.8K views
People Patterns or What I learned from Toastmasters by Sarah Allen
People Patterns or What I learned from ToastmastersPeople Patterns or What I learned from Toastmasters
People Patterns or What I learned from Toastmasters
Sarah Allen1.2K views
Blazing Cloud: Agile Product Development by Sarah Allen
Blazing Cloud: Agile Product DevelopmentBlazing Cloud: Agile Product Development
Blazing Cloud: Agile Product Development
Sarah Allen1.9K views
Crowdsourced Transcription Landscape by Sarah Allen
Crowdsourced Transcription LandscapeCrowdsourced Transcription Landscape
Crowdsourced Transcription Landscape
Sarah Allen808 views
Lessons Learned Future Thoughts by Sarah Allen
Lessons Learned Future ThoughtsLessons Learned Future Thoughts
Lessons Learned Future Thoughts
Sarah Allen3K views
Mobile Web Video by Sarah Allen
Mobile Web VideoMobile Web Video
Mobile Web Video
Sarah Allen2.1K views

Building a Ruby Gem

  • 1. C L A S S 6 Building a Gem
  • 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. 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. 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. 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. 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. Gem Resources  Rdoc  http://rdoc.sourceforge.net/doc/index.html  gem server  http://localhost:8808  publish your gems  http://gemcutter.org/
  • 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. T I M E T O P A R T Y . Thank You!