What Are Ruby Gems?6:08 with Jason Seifer
In Ruby, a gem is a library that contains a specific piece of functionality as well as any files or assets related to that functionality. Gems can be found for all sorts of common functionality in an application -- things like handling money and currency, integrating with credit card processing, tools to make ruby coding even easier, and more. You could write these things yourself but one big benefit to using a gem instead is that it saves time.
[MUSIC] 0:00 In Ruby, a Gem is a library that contains a specific piece of functionality 0:04 as well as any files or assets related to that functionality. 0:09 Gems can be found for all sorts of common things that you'd want to do 0:14 in an application, things like handling money and currency, integrating with 0:17 credit card processing, tools to make Ruby coding even easier, and more. 0:22 You could write these things yourself, 0:27 but one big benefit to using a Gem instead is that it saves time. 0:29 The main place that gems are found is rubygems.org. 0:34 Let's take a quick look at RubyGems now. 0:37 Now here we have the main rubygems.org website. 0:41 Now the instructions on here are pretty clear. 0:45 You can find, install, and even publish your own RubyGems. 0:47 Now, the main focus of this site is the big search 0:53 box right in the center of the screen. 0:56 This is how you'll find most of the Gems that you want to work with. 0:59 Let's say we wanted to install a Gem to work with money and currency. 1:03 We can search Gems and find money, if only it were that easy in real life. 1:09 Now once we search, we see any exact matches for 1:16 Gem names that come up and then, a small description of what the library does. 1:20 Here, we see it's a Ruby library for dealing with money and 1:25 currency conversion. 1:29 Over on the right-hand side of the screen, we'll see the number of downloads. 1:32 Now this can be a good indicator of the popularity of a particular Gem. 1:36 Gems with more downloads will be more popular, and 1:41 it can be reasonably assumed that they're maintained more often than other Gems. 1:44 Now as we scroll down this page, we'll see less exact matches and 1:50 these results are paginated, so 1:55 this is only displaying one through 30, of 134 total Gems. 1:58 Now as we scroll down, we see the less exact matches, money-rails 2:04 provides integration of Ruby money in a rails application. 2:09 Once we find a Gem that we want, we can click into it and 2:15 see a more thorough description. 2:18 On the left side, the most recent versions will be shown. 2:19 Now we can see that this Gem is up to version 6.6.1, and 2:24 the most recent version was released on July 27th, 2015. 2:29 If we click in, we can see all of the different versions of this Gem, 2:34 and it was released originally on June 8th, 2005. 2:40 So this Gem has been released and maintained for about ten years. 2:45 On the right side of the screen, we have runtime and development dependencies. 2:51 A runtime dependency will only be installed if the Gem 2:57 needs to be used in an application. 3:01 So we can see that the Ruby Money Gem depends on the i18n Gem. 3:05 i18n stands for internationalization. 3:11 Now we only need that gem to be installed as well if we're just going to use 3:15 the Money Gem. 3:19 However, you'll see below that, 3:20 there's a development dependency section of the screen and 3:22 this shows that the Gem depends on bundler, kramdown, rake, rspec, and yard. 3:26 We only need to worry about those if we plan 3:33 on doing development against this Gem. 3:36 In order to just use it, 3:41 all that we would need installed besides the Gem itself is i18n. 3:42 When we install the Gem, 3:47 any dependencies that are needed at runtime will also be installed. 3:49 We'll learn a little bit more about that later. 3:55 Now we can also see if we click back to the homepage, there's a stats section. 4:01 If we click in there, 4:06 we can see the most popular Gems that have been downloaded on rubygems.org. 4:07 This is based on the total number of downloads and 4:12 we can see the most popular Gem is Rake. 4:15 Rake comes with Ruby and is a task runner. 4:19 The scope of Rake is a little bit outside of this course, 4:23 but it is one of the most popular Gems as well as Rails. 4:28 You may have heard of Ruby on Rails. 4:33 Now if there's another functionality that we want, we can search for Gems. 4:38 Let's say we want to use a Gem for interpreting JSON outside of the standard 4:42 library, well, we could search for and find many different JSON Gems. 4:48 And then we could click into them and read a little bit more about them if we want to 4:54 and make the determination about whether or not we wanna use these in our programs. 4:59 Another source for finding Gems to work on is Ruby toolbox. 5:05 The Ruby toolbox shows Gems by category and popularity. 5:10 We could click on the categories section, and it will have by name and by group. 5:16 So for example, if we were looking for a different testing framework, 5:23 we could click in to the testing framework section and then, 5:27 Unit Test Frameworks and this will show us ranked by order of popularity, 5:30 the different Gems that are available as a testing framework. 5:37 We can see that the RSpec Gem is one of the most popular. 5:41 It had it's first release about seven years ago, and the most 5:46 current version was released about a month ago, as of the time of this recording. 5:49 It will also show the number of watchers and forks on GitHub. 5:54 As we scroll down, we see other testing frameworks as well, 5:59 and the description of the Gem is right below the Gem Name. 6:02
You need to sign up for Treehouse in order to download course files.Sign up