Man With Code 👨‍💻

In which I occasionally teach you things.

Programming With Ruby Episode 11, Ruby Projects

Series: Ruby Programming

Covered In This Episode: Transcript: Hello Everybody and welcome to Programming With Ruby Episode 11, Ruby Projects. I'm Tyler, and this video is brought to you by manwithcode.com. Despite what the name may imply, this episode is not about making projects in ruby, but finding and using projects other people have made. I will be showing you rubyforge.org and github.com, both places have many different and useful projects hosted. I will also be showing you how to use rubygems, arguably the easiest and most popular way of installing, managing, and keeping up to date various ruby libraries, tools, etc. which rubygems calls gems. And finally you will learn how to use the code you find! Lets get started! Finding Projects - Rubyforge Rubyforge is one of the most popular hosting sites for ruby projects. (It is also where most gems are hosted) Just navigate over to http://rubyforge.org to get started If you want to find a project, you have a few options. First is the search box located at the top right of the website. Second is the project tree where you can find projects by the category they are in. Third is the most popular projects on the homepage, which can be helpful from time to time. If you find a project that you like, you can download it, or install it as a gem if it is available. Both of which will be covered a little later in this tutorial. Finding Projects - GitHub Github is another project hosting site, that easily lets developers collaborate using the version control system, git. Github has been gaining a lot of popularity with Ruby programmers lately and you can find many Ruby projects here. GitHub is located at http://github.com GitHub has search functionality, and most popular like Rubyforge, but it is a little more comprehensive. GitHub also offers nice graphs and many download options depending on your needs. Using Rubygems To start using rubygems, first you have to install it. If you installed via a one-click installer you probably already have it. To check if you have it installed, open your command prompt and enter "gem". If nothing comes up, it is not installed. If you are on Debian or a variant of it (such as Ubuntu) this command will get you rubygems: sudo apt-get install rubygems Otherwise go to http://rubygems.org/ and download rubygems from there. After you've installed, run the command: gem to make sure the installation succeed. If not you may have to add rubygems to your PATH, a quick Google search will tell you how. For this example I you will install the gem hpricot, which parses HTML. simply use the command: gem install hpricot or sudo gem install hpricot It should install successfully, and now you can start using it in your code! But before we do that, I would like to show you a few more features or rubygems. "gem list" lists all the gems you have installed "gem uninstall gem" uninstalls the specified gem "gem update" updates all your gems "gem help commands" shows all commands that rubygems has, so you can explore on your own! Using the code Now that you have installed a gem, or downloaded a projects source code, you can use it in your own programs. To obtain access to an installed gem, or the source file add the following line to the top of your program: [ruby] require 'rubygems' require 'name' # Name can be a gem or a source file [/ruby] if you are just using a source file, you don't need to require rubygems example: [ruby] require 'rubygems' require 'hpricot' [/ruby] If you are loading a file that can change, use load: load 'name' # Name can be a gem or a source file Note that I said source file. This means that you can separate your own code into different files and load them in using the load or require methods! Now we have reached that sad sad time, when the episode starts ending. If you have any question, comments, or suggestions leave a comment on this page, or send me an email at [email protected] Please do not forget to donate, a small $5 or $10 donation will help more than you realize! Thanks for watching, Goodbye.

Comments

Laurance on

This tutorial is great man~

Tyler on

Thanks! :)

Universal.localhost on

Hey Tyler, I am learning ruby from your tutorials. I am an experienced developer on Java hence like your fast paced teaching. I realized that most of the hacking at hackathons and startupweekends are done in Ruby & Rails hence decided to learn it. :)

Tyler on

Nice! Have fun! :) I hope what I've put up here is helpful to you. Check out <a href="http://www.sinatrarb.com/" title="Sinatra" target="_blank" rel="nofollow">Sinatra</a> too, if you haven't already, that's much simpler than Rails and might be better for doing hackathons :P