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

What's hot (20)

PPTX
Martin Splitt "A short history of the web"
Fwdays
 
PPTX
The JSON REST API for WordPress
Taylor Lovett
 
PDF
CouchDB: A NoSQL database
Rubyc Slides
 
PPT
Please dont touch-3.6-jsday
Francesco Fullone
 
DOCX
Node js getting started
Pallavi Srivastava
 
PDF
Your first sinatra app
Rubyc Slides
 
PDF
Real-time search in Drupal. Meet Elasticsearch
Alexei Gorobets
 
PPTX
[Blibli Brown Bag] Nodejs - The Other Side of Javascript
Irfan Maulana
 
PPTX
PHP Indonesia - Nodejs Web Development
Irfan Maulana
 
PPT
Node js
Chirag Parmar
 
PDF
Afrimadoni the power of docker
PHP Indonesia
 
PDF
Apache Sling as an OSGi-powered REST middleware
Robert Munteanu
 
PDF
Rack
Sarah Allen
 
PDF
Getting started with node JS
Hamdi Hmidi
 
PDF
OpenERP and Perl
OpusVL
 
PPTX
Node js crash course session 2
Abdul Rahman Masri Attal
 
PDF
Ng init | EPI Sousse
Hamdi Hmidi
 
PPTX
Before start
Medhat Dawoud
 
PPTX
Intro to Rails and MVC
Sarah Allen
 
PDF
High Performance Front-End Development
drywallbmb
 
Martin Splitt "A short history of the web"
Fwdays
 
The JSON REST API for WordPress
Taylor Lovett
 
CouchDB: A NoSQL database
Rubyc Slides
 
Please dont touch-3.6-jsday
Francesco Fullone
 
Node js getting started
Pallavi Srivastava
 
Your first sinatra app
Rubyc Slides
 
Real-time search in Drupal. Meet Elasticsearch
Alexei Gorobets
 
[Blibli Brown Bag] Nodejs - The Other Side of Javascript
Irfan Maulana
 
PHP Indonesia - Nodejs Web Development
Irfan Maulana
 
Node js
Chirag Parmar
 
Afrimadoni the power of docker
PHP Indonesia
 
Apache Sling as an OSGi-powered REST middleware
Robert Munteanu
 
Getting started with node JS
Hamdi Hmidi
 
OpenERP and Perl
OpusVL
 
Node js crash course session 2
Abdul Rahman Masri Attal
 
Ng init | EPI Sousse
Hamdi Hmidi
 
Before start
Medhat Dawoud
 
Intro to Rails and MVC
Sarah Allen
 
High Performance Front-End Development
drywallbmb
 

Similar to 11 Ruby Gems (20)

PPTX
Creating Ruby Gems
Flatiron School
 
DOCX
Install Guide
Santosh Kiran Beyagudem
 
PDF
Everything-as-code - A polyglot adventure
QAware GmbH
 
PDF
Everything-as-code. A polyglot adventure. #DevoxxPL
Mario-Leander Reimer
 
PDF
Gemification for Ruby 2.5/3.0
Hiroshi SHIBATA
 
PPTX
Exploring Ruby on Rails and PostgreSQL
Barry Jones
 
PPTX
Jekyll, static websites generator
Francesco Napoletano
 
KEY
Contributing to rails
Lukas Eppler
 
PDF
The Future of library dependency manageement of Ruby
Hiroshi SHIBATA
 
PDF
SELENIUM CONF -PALLAVI SHARMA - 2024.pdf
Pallavi Sharma
 
PPT
First app
Benjamin Taylor
 
PDF
Agile sites311training
Michele Sciabarrà
 
KEY
Week6
reneedv
 
PDF
Writing a Ruby Gem for beginners
ConFoo
 
PPTX
Modeling Tricks My Relational Database Never Taught Me
David Boike
 
PDF
full-stack-webapp-testing-with-selenium-and-rails.pdf
Brian Takita
 
PDF
Web Development with Python and Django
Michael Pirnat
 
PPTX
JavaScript : A trending scripting language
AbhayDhupar
 
KEY
An introduction to Rails 3
Blazing Cloud
 
PPT
Jasig rubyon rails
_zaMmer_
 
Creating Ruby Gems
Flatiron School
 
Everything-as-code - A polyglot adventure
QAware GmbH
 
Everything-as-code. A polyglot adventure. #DevoxxPL
Mario-Leander Reimer
 
Gemification for Ruby 2.5/3.0
Hiroshi SHIBATA
 
Exploring Ruby on Rails and PostgreSQL
Barry Jones
 
Jekyll, static websites generator
Francesco Napoletano
 
Contributing to rails
Lukas Eppler
 
The Future of library dependency manageement of Ruby
Hiroshi SHIBATA
 
SELENIUM CONF -PALLAVI SHARMA - 2024.pdf
Pallavi Sharma
 
First app
Benjamin Taylor
 
Agile sites311training
Michele Sciabarrà
 
Week6
reneedv
 
Writing a Ruby Gem for beginners
ConFoo
 
Modeling Tricks My Relational Database Never Taught Me
David Boike
 
full-stack-webapp-testing-with-selenium-and-rails.pdf
Brian Takita
 
Web Development with Python and Django
Michael Pirnat
 
JavaScript : A trending scripting language
AbhayDhupar
 
An introduction to Rails 3
Blazing Cloud
 
Jasig rubyon rails
_zaMmer_
 
Ad

More from Deepak Hagadur Bheemaraju (10)

PPTX
12 Introduction to Rails
Deepak Hagadur Bheemaraju
 
PPTX
10 Networking
Deepak Hagadur Bheemaraju
 
PPTX
9 Inputs & Outputs
Deepak Hagadur Bheemaraju
 
PPTX
8 Exception Handling
Deepak Hagadur Bheemaraju
 
PPTX
7 Methods and Functional Programming
Deepak Hagadur Bheemaraju
 
PPTX
6 Object Oriented Programming
Deepak Hagadur Bheemaraju
 
PPTX
5 Statements and Control Structures
Deepak Hagadur Bheemaraju
 
PPTX
4 Expressions and Operators
Deepak Hagadur Bheemaraju
 
PPTX
3 Datatypes
Deepak Hagadur Bheemaraju
 
12 Introduction to Rails
Deepak Hagadur Bheemaraju
 
9 Inputs & Outputs
Deepak Hagadur Bheemaraju
 
8 Exception Handling
Deepak Hagadur Bheemaraju
 
7 Methods and Functional Programming
Deepak Hagadur Bheemaraju
 
6 Object Oriented Programming
Deepak Hagadur Bheemaraju
 
5 Statements and Control Structures
Deepak Hagadur Bheemaraju
 
4 Expressions and Operators
Deepak Hagadur Bheemaraju
 
Ad

Recently uploaded (20)

PDF
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.06.25.pdf
TechSoup
 
PDF
Lesson 1 - Nature of Inquiry and Research.pdf
marvinnbustamante1
 
PPTX
Natural Language processing using nltk.pptx
Ramakrishna Reddy Bijjam
 
PPTX
Different types of inheritance in odoo 18
Celine George
 
PPTX
Exploring Linear and Angular Quantities and Ergonomic Design.pptx
AngeliqueTolentinoDe
 
PPTX
Introduction to Indian Writing in English
Trushali Dodiya
 
DOCX
Lesson 1 - Nature and Inquiry of Research
marvinnbustamante1
 
PPTX
Navigating English Key Stage 2 lerning needs.pptx
JaysonClosa3
 
PPTX
Lesson 1 Cell (Structures, Functions, and Theory).pptx
marvinnbustamante1
 
PPTX
PLANNING A HOSPITAL AND NURSING UNIT.pptx
PRADEEP ABOTHU
 
PPTX
Light Reflection and Refraction- Activities - Class X Science
SONU ACADEMY
 
PPTX
Ward Management: Patient Care, Personnel, Equipment, and Environment.pptx
PRADEEP ABOTHU
 
PDF
Introduction presentation of the patentbutler tool
MIPLM
 
PPTX
Marketing Management PPT Unit 1 and Unit 2.pptx
Sri Ramakrishna College of Arts and science
 
PDF
DIGESTION OF CARBOHYDRATES ,PROTEINS AND LIPIDS
raviralanaresh2
 
PDF
Vani - The Voice of Excellence - Jul 2025 issue
Savipriya Raghavendra
 
PDF
AI-assisted IP-Design lecture from the MIPLM 2025
MIPLM
 
PPTX
Life and Career Skills Lesson 2.pptxProtective and Risk Factors of Late Adole...
ryangabrielcatalon40
 
PDF
I3PM Industry Case Study Siemens on Strategic and Value-Oriented IP Management
MIPLM
 
PPTX
How to Add a Custom Button in Odoo 18 POS Screen
Celine George
 
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.06.25.pdf
TechSoup
 
Lesson 1 - Nature of Inquiry and Research.pdf
marvinnbustamante1
 
Natural Language processing using nltk.pptx
Ramakrishna Reddy Bijjam
 
Different types of inheritance in odoo 18
Celine George
 
Exploring Linear and Angular Quantities and Ergonomic Design.pptx
AngeliqueTolentinoDe
 
Introduction to Indian Writing in English
Trushali Dodiya
 
Lesson 1 - Nature and Inquiry of Research
marvinnbustamante1
 
Navigating English Key Stage 2 lerning needs.pptx
JaysonClosa3
 
Lesson 1 Cell (Structures, Functions, and Theory).pptx
marvinnbustamante1
 
PLANNING A HOSPITAL AND NURSING UNIT.pptx
PRADEEP ABOTHU
 
Light Reflection and Refraction- Activities - Class X Science
SONU ACADEMY
 
Ward Management: Patient Care, Personnel, Equipment, and Environment.pptx
PRADEEP ABOTHU
 
Introduction presentation of the patentbutler tool
MIPLM
 
Marketing Management PPT Unit 1 and Unit 2.pptx
Sri Ramakrishna College of Arts and science
 
DIGESTION OF CARBOHYDRATES ,PROTEINS AND LIPIDS
raviralanaresh2
 
Vani - The Voice of Excellence - Jul 2025 issue
Savipriya Raghavendra
 
AI-assisted IP-Design lecture from the MIPLM 2025
MIPLM
 
Life and Career Skills Lesson 2.pptxProtective and Risk Factors of Late Adole...
ryangabrielcatalon40
 
I3PM Industry Case Study Siemens on Strategic and Value-Oriented IP Management
MIPLM
 
How to Add a Custom Button in Odoo 18 POS Screen
Celine George
 

11 Ruby Gems

  • 1. Deepak H B Full-Stack Developer Gmail: [email protected] 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 = '[email protected]‘ 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.