SlideShare a Scribd company logo
Deepak H B
Full-Stack Developer
Gmail: deepakhb2@gmail.com
Linkedin: http://in.linkedin.com/in/deepakhb
GitHub: https://github.com/deepakhb2
Ruby Gems
Introduction
• The gem command allows you to interact with RubyGems.
• Finding Gems
$gem search rails
• To find more info on gems
$gem search rails –d
• The install command downloads and installs the gem and any necessary
dependencies then builds documentation for the installed gems.
$gem install rails
• The list of installed gems can be viewed by running following command
$gem list
• Uninstallin gems
$gem uninstall rails
• If you uninstall a dependency of a gem, RubyGems will ask for
confirmation before uninstalling.
• The documents can be viewed by using ri.
$ri RBTree
• You can view the documentation for your installed gem in your browser
with server command
$gem server
Structure of Gem
• Each gem has name version and platform
• RubyGems platform is ruby, which means it works on
any platform Ruby runs on.
Compnents of Ruby gems
• Code
• Documentation
• Gemspec
Contd..
• Each gem follows the same standard structure of
code organization
freewill/
├── bin/
│ └── freewill
├── lib/
│ └── freewill.rb
├── test/
│ └── test_freewill.rb
├── README
├── Rakefile
└── freewill.gemspec
Contd..
• The lib directory contains the code for the gem
• The test or spec directory contains tests, depending on
which test framework the developer uses.
• The gem usually has a Rakefile. Which the rake program
used to automate tests, generate code and perform other
tasks.
• Documentation is usally included in the README and inline
with the code.
• The final piece is the gemspec, which contains the
information about the gem.
Contd..
% cat freewill.gemspec
Gem::Specification.new do |s|
s.name = 'freewill‘
s.version = '1.0.0'
s.summary = "Freewill!"
s.description = "I will choose Freewill!"
s.authors = ["Nick Quaranto"]
s.email = 'nick@quaran.to‘
s.homepage = 'http://example.com/freewill'
s.files = ["lib/freewill.rb", ...]
end
Making your own gem
• Creating publishing your own gem is simple thanks to the tools baked
right into RubyGems.
• Create the folder containing hello.gemspec, lib and lib/hello.rb
• The code for your package is placed inside lib.
• The code inside of lib/hello.rb is pretty bare bones.
$cat lib/hello.rb
• The content for gemspec needs to be updated.
• After you have created gemspec , you can build the gem from it.
gem build hello.gemspec
• Then you can install the generated gem locally to test it out.
• This gem can be pushed to to ruby gems by running following command.
Gem push hello-0.0.0.gem
Name your gem
Gem name Require statement Main class or module
fancy_require require 'fancy_require' FancyRequire
ruby_parser require 'ruby_parser' RubyParser
net-http-persistent require
'net/http/persistent' Net::HTTP::Persistent
rdoc-data require 'rdoc/data' RDoc::Data
autotest-growl require 'autotest/growl' Autotest::Growl
net-http-digest_auth require
'net/http/digest_auth' Net::HTTP::DigestAuth
Contd..
• If you publish a gem on rubygems.org it may be removed if the
name is objectionalble, violates intellectual property or the
contents of the gem meet these criteria.
• You can also report such a gem on the RugyGems support site.
• Don’t use upper case letters.
• Use underscore for multiple words
– If a class or module has multiple words, use underscores to
separate them.
– This matches the file the user will require, making is easier for
the use to start using your gem.
Contd..
• Mix underscore and dashes appropriately.
– If your class or module has multiple words and your also adding
functionality to another gem, follow both of the rules above.
– Example, “net-http-digest_auth adds HTTP digest authentication
to net/http.
– The user will require “net/http/digest_aut” to use the extension
“Net::HTTP::DigestAuth.
• Use dashes for extensions.
– If your adding functionality to another gem, use a dash.
– This usually correspond to a / in the require statement and :: in
the name of your main class or module
Publishing to RubyGems.org
• The simplest way to distribute a gem for public consumption is to
use RubyGems.org.
• Gems that are published to RubyGems.org can be installed via the
gem install command.
• To begin, you will need to create an account on RubyGems.org.
• After creating the account, use your email and password when
pushing the gem.
• RubyGems saves the credentials in ~/.gem/credentials for you so
you only need to log in once.

More Related Content

KEY
Nodeconf npm 2011
PDF
LAWDI - Rogue Linked Data
KEY
MongoDB at RubyEnRails 2009
KEY
Rack
PPT
WordPress Harrisburg Meetup - Best Practices
KEY
doing_it_right() with WordPress
PPTX
Ruby On Rails Intro
PDF
Plack basics for Perl websites - YAPC::EU 2011
Nodeconf npm 2011
LAWDI - Rogue Linked Data
MongoDB at RubyEnRails 2009
Rack
WordPress Harrisburg Meetup - Best Practices
doing_it_right() with WordPress
Ruby On Rails Intro
Plack basics for Perl websites - YAPC::EU 2011

What's hot (20)

PPTX
Martin Splitt "A short history of the web"
PPTX
The JSON REST API for WordPress
PDF
CouchDB: A NoSQL database
PPT
Please dont touch-3.6-jsday
DOCX
Node js getting started
PDF
Your first sinatra app
PDF
Real-time search in Drupal. Meet Elasticsearch
PPTX
[Blibli Brown Bag] Nodejs - The Other Side of Javascript
PPTX
PHP Indonesia - Nodejs Web Development
PPT
Node js
PDF
Afrimadoni the power of docker
PDF
Apache Sling as an OSGi-powered REST middleware
PDF
PDF
Getting started with node JS
PDF
OpenERP and Perl
PPTX
Node js crash course session 2
PDF
Ng init | EPI Sousse
PPTX
Before start
PPTX
Intro to Rails and MVC
PDF
High Performance Front-End Development
Martin Splitt "A short history of the web"
The JSON REST API for WordPress
CouchDB: A NoSQL database
Please dont touch-3.6-jsday
Node js getting started
Your first sinatra app
Real-time search in Drupal. Meet Elasticsearch
[Blibli Brown Bag] Nodejs - The Other Side of Javascript
PHP Indonesia - Nodejs Web Development
Node js
Afrimadoni the power of docker
Apache Sling as an OSGi-powered REST middleware
Getting started with node JS
OpenERP and Perl
Node js crash course session 2
Ng init | EPI Sousse
Before start
Intro to Rails and MVC
High Performance Front-End Development
Ad

Similar to 11 Ruby Gems (20)

KEY
Week6
PDF
Writing a Ruby Gem for beginners
PPTX
Creating Ruby Gems
PPTX
RubyConfBD 2013 decouple, bundle and share with ruby gems
PDF
How to make a Ruby Gem - Austin on Rails, January 2014
ODP
Build-a-Gem Workshop
ODP
Build-a-Gem Workshop
PPTX
Chennai.rb feb 2016
PPTX
Building a Ruby Gem
PPTX
Ruby version manager
PDF
Extracting ruby gem
PDF
Create your-own-gem-with-github-jeweler-rubygems
PDF
Gems on Ruby
PDF
Gem That (2009)
PDF
Gemification for Ruby 2.5/3.0
KEY
from(0).to('rubygems.org')
PDF
RubyGems 3 & 4
KEY
Ruby gemsパッケージの作り方
DOCX
KEY
An introduction to Rails 3
Week6
Writing a Ruby Gem for beginners
Creating Ruby Gems
RubyConfBD 2013 decouple, bundle and share with ruby gems
How to make a Ruby Gem - Austin on Rails, January 2014
Build-a-Gem Workshop
Build-a-Gem Workshop
Chennai.rb feb 2016
Building a Ruby Gem
Ruby version manager
Extracting ruby gem
Create your-own-gem-with-github-jeweler-rubygems
Gems on Ruby
Gem That (2009)
Gemification for Ruby 2.5/3.0
from(0).to('rubygems.org')
RubyGems 3 & 4
Ruby gemsパッケージの作り方
An introduction to Rails 3
Ad

More from Deepak Hagadur Bheemaraju (10)

PPTX
12 Introduction to Rails
PPTX
PPTX
9 Inputs & Outputs
PPTX
8 Exception Handling
PPTX
7 Methods and Functional Programming
PPTX
6 Object Oriented Programming
PPTX
5 Statements and Control Structures
PPTX
4 Expressions and Operators
PPTX
12 Introduction to Rails
9 Inputs & Outputs
8 Exception Handling
7 Methods and Functional Programming
6 Object Oriented Programming
5 Statements and Control Structures
4 Expressions and Operators

Recently uploaded (20)

PPTX
master seminar digital applications in india
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
01-Introduction-to-Information-Management.pdf
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PDF
Basic Mud Logging Guide for educational purpose
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
RMMM.pdf make it easy to upload and study
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Classroom Observation Tools for Teachers
master seminar digital applications in india
VCE English Exam - Section C Student Revision Booklet
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
STATICS OF THE RIGID BODIES Hibbelers.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
Final Presentation General Medicine 03-08-2024.pptx
PPH.pptx obstetrics and gynecology in nursing
01-Introduction-to-Information-Management.pdf
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
Week 4 Term 3 Study Techniques revisited.pptx
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Basic Mud Logging Guide for educational purpose
FourierSeries-QuestionsWithAnswers(Part-A).pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
RMMM.pdf make it easy to upload and study
human mycosis Human fungal infections are called human mycosis..pptx
O7-L3 Supply Chain Operations - ICLT Program
Classroom Observation Tools for Teachers

11 Ruby Gems

  • 1. Deepak H B Full-Stack Developer Gmail: deepakhb2@gmail.com Linkedin: http://in.linkedin.com/in/deepakhb GitHub: https://github.com/deepakhb2
  • 3. Introduction • The gem command allows you to interact with RubyGems. • Finding Gems $gem search rails • To find more info on gems $gem search rails –d • The install command downloads and installs the gem and any necessary dependencies then builds documentation for the installed gems. $gem install rails • The list of installed gems can be viewed by running following command $gem list • Uninstallin gems $gem uninstall rails • If you uninstall a dependency of a gem, RubyGems will ask for confirmation before uninstalling. • The documents can be viewed by using ri. $ri RBTree • You can view the documentation for your installed gem in your browser with server command $gem server
  • 4. Structure of Gem • Each gem has name version and platform • RubyGems platform is ruby, which means it works on any platform Ruby runs on. Compnents of Ruby gems • Code • Documentation • Gemspec
  • 5. Contd.. • Each gem follows the same standard structure of code organization freewill/ ├── bin/ │ └── freewill ├── lib/ │ └── freewill.rb ├── test/ │ └── test_freewill.rb ├── README ├── Rakefile └── freewill.gemspec
  • 6. Contd.. • The lib directory contains the code for the gem • The test or spec directory contains tests, depending on which test framework the developer uses. • The gem usually has a Rakefile. Which the rake program used to automate tests, generate code and perform other tasks. • Documentation is usally included in the README and inline with the code. • The final piece is the gemspec, which contains the information about the gem.
  • 7. Contd.. % cat freewill.gemspec Gem::Specification.new do |s| s.name = 'freewill‘ s.version = '1.0.0' s.summary = "Freewill!" s.description = "I will choose Freewill!" s.authors = ["Nick Quaranto"] s.email = 'nick@quaran.to‘ s.homepage = 'http://example.com/freewill' s.files = ["lib/freewill.rb", ...] end
  • 8. Making your own gem • Creating publishing your own gem is simple thanks to the tools baked right into RubyGems. • Create the folder containing hello.gemspec, lib and lib/hello.rb • The code for your package is placed inside lib. • The code inside of lib/hello.rb is pretty bare bones. $cat lib/hello.rb • The content for gemspec needs to be updated. • After you have created gemspec , you can build the gem from it. gem build hello.gemspec • Then you can install the generated gem locally to test it out. • This gem can be pushed to to ruby gems by running following command. Gem push hello-0.0.0.gem
  • 9. Name your gem Gem name Require statement Main class or module fancy_require require 'fancy_require' FancyRequire ruby_parser require 'ruby_parser' RubyParser net-http-persistent require 'net/http/persistent' Net::HTTP::Persistent rdoc-data require 'rdoc/data' RDoc::Data autotest-growl require 'autotest/growl' Autotest::Growl net-http-digest_auth require 'net/http/digest_auth' Net::HTTP::DigestAuth
  • 10. Contd.. • If you publish a gem on rubygems.org it may be removed if the name is objectionalble, violates intellectual property or the contents of the gem meet these criteria. • You can also report such a gem on the RugyGems support site. • Don’t use upper case letters. • Use underscore for multiple words – If a class or module has multiple words, use underscores to separate them. – This matches the file the user will require, making is easier for the use to start using your gem.
  • 11. Contd.. • Mix underscore and dashes appropriately. – If your class or module has multiple words and your also adding functionality to another gem, follow both of the rules above. – Example, “net-http-digest_auth adds HTTP digest authentication to net/http. – The user will require “net/http/digest_aut” to use the extension “Net::HTTP::DigestAuth. • Use dashes for extensions. – If your adding functionality to another gem, use a dash. – This usually correspond to a / in the require statement and :: in the name of your main class or module
  • 12. Publishing to RubyGems.org • The simplest way to distribute a gem for public consumption is to use RubyGems.org. • Gems that are published to RubyGems.org can be installed via the gem install command. • To begin, you will need to create an account on RubyGems.org. • After creating the account, use your email and password when pushing the gem. • RubyGems saves the credentials in ~/.gem/credentials for you so you only need to log in once.